Load the entity for the CIMI::Model
model
, or create a new one if none exists yet
# File lib/db/entity.rb, line 56 def self.retrieve(model) unless model.id raise "Can not retrieve entity for #{model.class.name} without an id" end h = model_hash(model) entity = Provider::lookup.entities_dataset.first(h) unless entity h[:provider_id] = Provider::lookup.id entity = Entity.new(h) end entity end
# File lib/db/entity.rb, line 46 def after_initialize if ent_properties self.properties = JSON::parse(ent_properties) else self.properties = {} end end
# File lib/db/entity.rb, line 41 def before_save self.ent_properties = properties.to_json super end
# File lib/db/entity.rb, line 36 def properties=(v) # Make sure @properties is always a Hash @properties = v || {} end
# File lib/db/entity.rb, line 28 def to_hash retval = {} retval.merge!(:name => self.name) if !self.name.nil? retval.merge!(:description => self.description) if !self.description.nil? retval.merge!(:property => JSON::parse(self.ent_properties)) if !self.ent_properties.nil? retval end