class Deltacloud::Database::Entity

Attributes

properties[RW]

Public Class Methods

retrieve(model) click to toggle source

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

Public Instance Methods

after_initialize() click to toggle source
# File lib/db/entity.rb, line 46
def after_initialize
  if ent_properties
    self.properties = JSON::parse(ent_properties)
  else
    self.properties = {}
  end
end
before_save() click to toggle source
# File lib/db/entity.rb, line 41
def before_save
  self.ent_properties = properties.to_json
  super
end
properties=(v) click to toggle source
# File lib/db/entity.rb, line 36
def properties=(v)
  # Make sure @properties is always a Hash
  @properties = v || {}
end
to_hash() click to toggle source
# 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