Class: Deltacloud::Database::Entity
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- Deltacloud::Database::Entity
show all
- Defined in:
- lib/db/entity.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#properties ⇒ Object
Returns the value of attribute properties.
21
22
23
|
# File 'lib/db/entity.rb', line 21
def properties
@properties
end
|
Class Method Details
.inherited(subclass) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/db/entity.rb', line 70
def self.inherited(subclass)
super
@@model_entity_map ||= Hash.new(Entity)
n = subclass.name.split('::').last
if k = CIMI::Model::const_get(n)
@@model_entity_map[k] = subclass
end
end
|
.retrieve(model) ⇒ Object
Load the entity for the CIMI::Model model
, or create a new one if none exists yet
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/db/entity.rb', line 57
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 = @@model_entity_map[model.class].new(h)
end
entity
end
|
Instance Method Details
#after_initialize ⇒ Object
46
47
48
49
50
51
52
53
|
# File 'lib/db/entity.rb', line 46
def after_initialize
super
if ent_properties
self.properties = JSON::parse(ent_properties)
else
self.properties = {}
end
end
|
#before_save ⇒ Object
41
42
43
44
|
# File 'lib/db/entity.rb', line 41
def before_save
self.ent_properties = properties.to_json
super
end
|
#to_hash ⇒ Object
28
29
30
31
32
33
34
|
# 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
|