Class: CIMI::Model::Base

Inherits:
Resource show all
Extended by:
CollectionMethods, Deltacloud::Helpers::Database
Includes:
Helpers::SelectBaseMethods
Defined in:
lib/cimi/models/base.rb

Constant Summary

Constants included from Deltacloud::Helpers::Database

Deltacloud::Helpers::Database::DATABASE_COLLECTIONS

Constants inherited from Resource

Resource::CMWG_NAMESPACE

Instance Attribute Summary

Attributes inherited from Resource

#attribute_values

Instance Method Summary collapse

Methods included from Deltacloud::Helpers::Database

current_db, current_provider, provides?, test_environment?

Methods included from Deltacloud::Helpers::Drivers

#driver, #driver_class, #driver_class_name, #driver_name, #driver_source_name, #driver_symbol, included, #provider_name

Methods included from CollectionMethods

acts_as_root_entity, all, collection_class, collection_class=, list

Methods included from Helpers::SelectBaseMethods

#select_attributes

Methods inherited from Resource

#[], add_attributes!, all_uri, #base_id, base_schema, base_schema_cloned?, clone_base_schema, from_json, from_xml, inherited, parse, #prepare, resource_uri, to_json, #to_json, to_xml, #to_xml, xml_tag_name

Methods included from Schema::DSL

#array, #collection, #hash, #href, #resource_attr, #scalar, #struct, #text

Methods included from Helpers::FilterResourceMethods

#filter_by, #parse_filter_opts

Methods included from Helpers::SelectResourceMethods

#select_by, #select_by_arr_index, #select_by_arr_range

Constructor Details

#initialize(values = {}) ⇒ Base


92
93
94
95
# File 'lib/cimi/models/base.rb', line 92

def initialize(values = {})
  super(values)
  retrieve_entity
end

Instance Method Details

#[]=(a, v) ⇒ Object


97
98
99
100
101
# File 'lib/cimi/models/base.rb', line 97

def []=(a, v)
  v = super
  retrieve_entity if a == :id
  v
end

#destroyObject

Destroy the database attributes for this model


116
117
118
119
# File 'lib/cimi/models/base.rb', line 116

def destroy
  @entity.destroy
  self
end

#extract_properties!(data) ⇒ Object

FIXME: Kludge around the fact that we do not have proper *Create objects that deserialize properties by themselves


123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/cimi/models/base.rb', line 123

def extract_properties!(data)
  h = {}
  if data['property']
    # Data came from XML
    h = data['property'].inject({}) do |r,v|
      r[v['key']] = v['content']
      r
    end
  elsif data['properties']
    h = data['properties']
  end
  property ||= {}
  property.merge!(h)
end

#saveObject

Save the common attributes name, description, and properties to the database


105
106
107
108
109
110
111
112
113
# File 'lib/cimi/models/base.rb', line 105

def save
  if @entity
    @entity.name = name
    @entity.description = description
    @entity.properties = property
    @entity.save
  end
  self
end