deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@redhat.com
Subject [PATCH 3/8] CIMI collections: create embedded collections within their containing classes
Date Fri, 09 Nov 2012 04:18:42 GMT
From: David Lutterkort <lutter@redhat.com>

We had two NetworkPortCollections: one being the toplevel one, the other
being the collection of ports within a Network. Both classes were being
generated as CIMI::Model::NetworkPortCollection.

This changes it so that the toplevel collection will be
CIMI::Model::NetworkPortCollection, while the other will be
CIMI::Model::Network::NetworPortCollection.

This double-defining of CIMI::Model::NetworkPortCollection caused server
errors when retrieving the toplevel NetworkPortCollection
---
 server/lib/cimi/models/collection.rb |    3 ++-
 server/lib/cimi/models/schema.rb     |    6 +++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/server/lib/cimi/models/collection.rb b/server/lib/cimi/models/collection.rb
index 70692ca..c7f3b21 100644
--- a/server/lib/cimi/models/collection.rb
+++ b/server/lib/cimi/models/collection.rb
@@ -75,8 +75,9 @@ module CIMI::Model
 
     def self.generate(model_class, opts = {})
       model_name = model_class.name.split("::").last
+      scope = opts[:scope] || CIMI::Model
       coll_class = Class.new(CIMI::Model::Collection)
-      CIMI::Model.const_set(:"#{model_name}Collection", coll_class)
+      scope.const_set(:"#{model_name}Collection", coll_class)
       coll_class.entry_name = model_name.underscore.pluralize.to_sym
       coll_class.embedded = opts[:embedded]
       entry_schema = model_class.schema
diff --git a/server/lib/cimi/models/schema.rb b/server/lib/cimi/models/schema.rb
index fe4ed07..115e236 100644
--- a/server/lib/cimi/models/schema.rb
+++ b/server/lib/cimi/models/schema.rb
@@ -218,11 +218,14 @@ class CIMI::Model::Schema
 
   class Collection < Attribute
     def initialize(name, opts = {})
+      params = {}
+      params[:scope] = opts.delete(:scope)
       super(name, opts)
       unless opts[:class]
         raise "Specify the class of collection entries using :class"
       end
-      @collection_class = CIMI::Model::Collection.generate(opts[:class], :embedded =>
true)
+      params[:embedded] = true
+      @collection_class = CIMI::Model::Collection.generate(opts[:class], params)
     end
 
     def from_xml(xml, model)
@@ -354,6 +357,7 @@ class CIMI::Model::Schema
     end
 
     def collection(name, opts={})
+      opts[:scope] = self.class
       add_attributes!([name, opts], Collection)
     end
   end
-- 
1.7.7.6


Mime
View raw message