Module: CIMI::Model::CollectionMethods
- Included in:
- Base
- Defined in:
- lib/cimi/models/collection.rb
Instance Method Summary collapse
- #acts_as_root_entity(opts = {}) ⇒ Object
- #all(context) ⇒ Object
- #collection_class ⇒ Object
- #collection_class=(klass) ⇒ Object
-
#list(context) ⇒ Object
Return a collection of entities.
Instance Method Details
#acts_as_root_entity(opts = {}) ⇒ Object
117 118 119 120 |
# 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) ⇒ Object
145 146 147 |
# File 'lib/cimi/models/collection.rb', line 145 def all(context) find :all, context end |
#collection_class ⇒ Object
113 114 115 |
# File 'lib/cimi/models/collection.rb', line 113 def collection_class @collection_class end |
#collection_class=(klass) ⇒ Object
109 110 111 |
# File 'lib/cimi/models/collection.rb', line 109 def collection_class=(klass) @collection_class = klass end |
#list(context) ⇒ Object
Return a collection of entities
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# 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 |