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
-
#inspect ⇒ Object
call-seq: inspect() => readable-string.
-
#set_key_value(k, v) ⇒ Object
call-seq: set_key_value(key, value).
Instance Method Details
#inspect ⇒ Object
call-seq:
inspect() => readable-string
Produce a readable string
306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/intermine/model.rb', line 306 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
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/intermine/model.rb', line 286 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 |