From: David Lutterkort <[email protected]>
We need to be able to alias some of the root entities since their name in
the CEP is different from the class name
---
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(-)
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
diff --git a/server/lib/cimi/models/collection.rb
b/server/lib/cimi/models/collection.rb
index 7e16d7f..806f6c1 100644
--- a/server/lib/cimi/models/collection.rb
+++ b/server/lib/cimi/models/collection.rb
@@ -72,9 +72,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
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
--
1.7.7.6