Module: InterMine::Metadata::SetHashKey

Included in:
ClassDescriptor, FieldDescriptor
Defined in:
lib/intermine/model.rb

Overview

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

:include:contact_header.rdoc

Instance Method Summary collapse

Instance Method Details

#inspectObject

call-seq:

inspect() => readable-string

Produce a readable string



310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/intermine/model.rb', line 310

def inspect
    parts = []
    self.instance_variables.each do |x|
        var = self.instance_variable_get(x)
        if var.is_a?(ClassDescriptor) || var.is_a?(Model)
            parts << x.to_s + "=" + var.to_s
        else
            parts << x.to_s + "=" + var.inspect
        end
    end
    return "<#{parts.join(' ')}>"
end

#set_key_value(k, v) ⇒ Object

call-seq:

set_key_value(key, value)

Set up instance variables based on the contents of a hash



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/intermine/model.rb', line 290

def set_key_value(k, v)
    if (k == "type")
        k = "dataType"
    end
    ## create and initialize an instance variable for this 
    ## key/value pair
    self.instance_variable_set("@#{k}", v) 
    ## create the getter that returns the instance variable
    self.class.send(:define_method, k, 
        proc{self.instance_variable_get("@#{k}")})  
    ## create the setter that sets the instance variable
    self.class.send(:define_method, "#{k}=", 
        proc{|v| self.instance_variable_set("@#{k}", v)})  
    return
end