module CIMI::Model::CollectionMethods

Public Instance Methods

acts_as_root_entity(opts = {}) click to toggle source
# File lib/cimi/models/collection.rb, line 117
def acts_as_root_entity(opts = {})
  self.collection_class = Collection.generate(self)
  CIMI::Model.register_as_root_entity! self, opts
end
all(context) click to toggle source
# File lib/cimi/models/collection.rb, line 145
def all(context)
  find :all, context
end
collection_class() click to toggle source
# File lib/cimi/models/collection.rb, line 113
def collection_class
  @collection_class
end
collection_class=(klass) click to toggle source
# File lib/cimi/models/collection.rb, line 109
def collection_class=(klass)
  @collection_class = klass
end
list(context) click to toggle source

Return a collection of entities

# File lib/cimi/models/collection.rb, line 123
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