Class: CIMI::Model::Base

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

Overview

We need to reopen Base and add some stuff to avoid circular dependencies

Constant Summary

Constants included from Deltacloud::Helpers::Database

Deltacloud::Helpers::Database::DATABASE_COLLECTIONS

Constants inherited from Resource

Resource::CMWG_NAMESPACE

Class Attribute Summary collapse

Attributes inherited from Resource

#attribute_values

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Deltacloud::Helpers::Database

current_db, current_provider, delete_attributes_for, extract_attribute_value, get_entity, load_attributes_for, provides?, store_attributes_for, 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 inherited from Resource

<<, #[], #[]=, add_attributes!, all_uri, base_schema, base_schema_cloned?, clone_base_schema, #filter_by, #filter_by_arr_index, #filter_by_arr_range, from_json, from_xml, inherited, #initialize, 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

Constructor Details

This class inherits a constructor from CIMI::Model::Resource

Class Attribute Details

.collection_classObject

Returns the value of attribute collection_class.



108
109
110
# File 'lib/cimi/models/collection.rb', line 108

def collection_class
  @collection_class
end

Class Method Details

.acts_as_root_entity(opts = {}) ⇒ Object



110
111
112
113
# File 'lib/cimi/models/collection.rb', line 110

def acts_as_root_entity(opts = {})
  self.collection_class = Collection.generate(self)
  CIMI::Model.register_as_root_entity! self, opts
end

.all(context) ⇒ Object



139
140
141
# File 'lib/cimi/models/collection.rb', line 139

def self.all(context)
  find(:all, context)
end

.list(context) ⇒ Object

Return a collection of entities



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/cimi/models/collection.rb', line 116

def list(context)
  entries = find(:all, context)
  desc = "#{self.name.split("::").last} Collection for the #{context.driver.name.capitalize} driver"
  acts_as_root_entity unless collection_class
  id = context.send("#{collection_class.entry_name}_url")
  ops = []
  cimi_entity = collection_class.entry_name.to_s.singularize
  cimi_create = "create_#{cimi_entity}_url"
  dcloud_create = context.deltacloud_create_method_for(cimi_entity)
  if(context.respond_to?(cimi_create) &&
     context.driver.respond_to?(dcloud_create)) ||
       provides?(cimi_entity)
    url = context.send(cimi_create)
    ops << { :rel => "add", :href => url }
  end
  collection_class.new(:id => id,
                       :count => entries.size,
                       :entries => entries,
                       :operations => ops,
                       :description => desc)
end

Instance Method Details

#filter_attributes(attr_list) ⇒ Object



282
283
284
285
286
287
288
289
# File 'lib/cimi/models/base.rb', line 282

def filter_attributes(attr_list)
  attrs = attr_list.inject({}) do |result, attr|
    attr = attr.to_s.underscore
    result[attr.to_sym] = self.send(attr) if self.respond_to?(attr)
    result
  end
  self.class.new(attrs)
end