deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject [6/9] git commit: CIMI collections: create embedded collections within their containing classes
Date Fri, 09 Nov 2012 19:49:39 GMT
CIMI collections: create embedded collections within their containing classes

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


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/b02acbd1
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/b02acbd1
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/b02acbd1

Branch: refs/heads/master
Commit: b02acbd1499623f2a22414d199f6c2209ca0bd47
Parents: 98c1482
Author: David Lutterkort <lutter@redhat.com>
Authored: Thu Nov 8 16:40:04 2012 -0800
Committer: David Lutterkort <lutter@redhat.com>
Committed: Fri Nov 9 11:48:42 2012 -0800

----------------------------------------------------------------------
 server/lib/cimi/models/collection.rb |    3 ++-
 server/lib/cimi/models/schema.rb     |    6 +++++-
 2 files changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b02acbd1/server/lib/cimi/models/collection.rb
----------------------------------------------------------------------
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

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b02acbd1/server/lib/cimi/models/schema.rb
----------------------------------------------------------------------
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


Mime
View raw message