deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject [8/10] git commit: CIMI models: allow passing options to acts_as_root_entity
Date Mon, 24 Sep 2012 23:52:48 GMT
CIMI models: allow passing options to acts_as_root_entity

We need to be able to alias some of the root entities since their name in
the CEP is different from the class name


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

Branch: refs/heads/master
Commit: c6b642b03ea07080f35b5d6322f06b666dd3b731
Parents: 6efdde5
Author: David Lutterkort <lutter@redhat.com>
Authored: Tue Sep 18 13:39:55 2012 -0700
Committer: David Lutterkort <lutter@redhat.com>
Committed: Mon Sep 24 16:33:40 2012 -0700

----------------------------------------------------------------------
 server/lib/cimi/models/base.rb            |   11 ++++++++---
 server/lib/cimi/models/collection.rb      |    4 ++--
 server/lib/cimi/models/entity_metadata.rb |    3 +--
 3 files changed, 11 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/c6b642b0/server/lib/cimi/models/base.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/base.rb b/server/lib/cimi/models/base.rb
index 92ad07b..e36ad6e 100644
--- a/server/lib/cimi/models/base.rb
+++ b/server/lib/cimi/models/base.rb
@@ -69,11 +69,16 @@ require 'json'
 
 module CIMI::Model
 
-  def self.register_as_root_entity!(name)
+  def self.register_as_root_entity!(klass, opts = {})
     @root_entities ||= []
-    @root_entities << name
+    @root_entities << klass
+    name = klass.name.split("::").last.pluralize
     unless CIMI::Model::CloudEntryPoint.href_defined?(name)
-      CIMI::Model::CloudEntryPoint.send(:href, name.underscore)
+      params = {}
+      if opts[:as]
+        params[:xml_name] = params[:json_name] = opts[:as]
+      end
+      CIMI::Model::CloudEntryPoint.send(:href, name.underscore, params)
     end
   end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/c6b642b0/server/lib/cimi/models/collection.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/collection.rb b/server/lib/cimi/models/collection.rb
index a6e1e36..6053f9f 100644
--- a/server/lib/cimi/models/collection.rb
+++ b/server/lib/cimi/models/collection.rb
@@ -77,9 +77,9 @@ module CIMI::Model
 
       attr_accessor :collection_class
 
-      def acts_as_root_entity
+      def acts_as_root_entity(opts = {})
         self.collection_class = Collection.generate(self)
-        CIMI::Model.register_as_root_entity! collection_class.entry_name.to_s.camelize
+        CIMI::Model.register_as_root_entity! self, opts
       end
 
       # Return a collection of entities

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/c6b642b0/server/lib/cimi/models/entity_metadata.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/entity_metadata.rb b/server/lib/cimi/models/entity_metadata.rb
index 1203001..2379e7d 100644
--- a/server/lib/cimi/models/entity_metadata.rb
+++ b/server/lib/cimi/models/entity_metadata.rb
@@ -38,8 +38,7 @@ class CIMI::Model::EntityMetadata < CIMI::Model::Base
   def self.find(id, context)
     entity_metadata = []
     if id == :all
-      CIMI::Model.root_entities.each do |entity|
-        entity_class = CIMI::Model.const_get("#{entity.singularize}")
+      CIMI::Model.root_entities.each do |entity_class|
         entity_metadata << entity_class.create_entity_metadata(context) if entity_class.respond_to?(:create_entity_metadata)
       end
       return entity_metadata


Mime
View raw message