module InterMine::Metadata::SetHashKey

A base module that provides helpers for setting up classes bases on the contents of a Hash

ClassDescriptors and FieldDescriptors are instantiated 
with hashes that provide their properties. This module
makes sure that the appropriate instance variables are set
author

Alex Kalderimis dev@intermine.org

homepage

www.intermine.org

Licence

Copyright (C) 2002-2011 FlyMine

This code may be freely distributed and modified under the terms of the GNU Lesser General Public Licence. This should be distributed with the code. See the LICENSE file for more information or www.gnu.org/copyleft/lesser.html.

Public Instance Methods

inspect() → readable-string click to toggle source

Produce a readable string

    # File lib/intermine/model.rb
310 def inspect
311     parts = []
312     self.instance_variables.each do |x|
313         var = self.instance_variable_get(x)
314         if var.is_a?(ClassDescriptor) || var.is_a?(Model)
315             parts << x.to_s + "=" + var.to_s
316         else
317             parts << x.to_s + "=" + var.inspect
318         end
319     end
320     return "<#{parts.join(' ')}>"
321 end
set_key_value(key, value) click to toggle source

Set up instance variables based on the contents of a hash

    # File lib/intermine/model.rb
290 def set_key_value(k, v)
291     if (k == "type")
292         k = "dataType"
293     end
294     ## create and initialize an instance variable for this
295     ## key/value pair
296     self.instance_variable_set("@#{k}", v) 
297     ## create the getter that returns the instance variable
298     self.class.send(:define_method, k, 
299         proc{self.instance_variable_get("@#{k}")})  
300     ## create the setter that sets the instance variable
301     self.class.send(:define_method, "#{k}=", 
302         proc{|v| self.instance_variable_set("@#{k}", v)})  
303     return
304 end