From ec5e4649b0326dccb6bb54a7aa45953ff0827f40 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Mon, 30 Jul 2012 12:47:42 +0200 Subject: [PATCH] bug #1397: Define DOCUMENT_TYPE in the child class --- src/oca/ruby/OpenNebula/Document.rb | 14 +++++++++----- src/oca/ruby/OpenNebula/DocumentPool.rb | 18 +++++++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/oca/ruby/OpenNebula/Document.rb b/src/oca/ruby/OpenNebula/Document.rb index f2e9e09245..8462c02262 100644 --- a/src/oca/ruby/OpenNebula/Document.rb +++ b/src/oca/ruby/OpenNebula/Document.rb @@ -18,15 +18,15 @@ require 'OpenNebula/Pool' module OpenNebula - # All subclasses must define the Document::TYPE constant. + # All subclasses must define the DOCUMENT_TYPE constant. # # @example # require 'OpenNebula/Document' # # module OpenNebula # class CustomObject < Document - # - # Document::TYPE = 400 + # + # DOCUMENT_TYPE = 400 # # end # end @@ -65,7 +65,7 @@ module OpenNebula # # @param [Nokogiri::XML::Node, REXML::Element] xml string # created by the build_xml() method - # @param [OpenNebula::Client] client the xml-rpc client + # @param [OpenNebula::Client] client the xml-rpc client # # @return [Document] the new object # @@ -94,7 +94,7 @@ module OpenNebula # @return [nil, OpenNebula::Error] nil in case of success, Error # otherwise def allocate(description) - super(DOCUMENT_METHODS[:allocate], description, TYPE) + super(DOCUMENT_METHODS[:allocate], description, document_type) end # Deletes the Document @@ -187,6 +187,10 @@ module OpenNebula end end + def document_type + self.class::DOCUMENT_TYPE + end + private def set_publish(published) diff --git a/src/oca/ruby/OpenNebula/DocumentPool.rb b/src/oca/ruby/OpenNebula/DocumentPool.rb index 3654947ed6..3b428aa698 100644 --- a/src/oca/ruby/OpenNebula/DocumentPool.rb +++ b/src/oca/ruby/OpenNebula/DocumentPool.rb @@ -18,7 +18,7 @@ require 'OpenNebula/Pool' module OpenNebula - # All subclasses must define the DocumentPool::TYPE constant + # All subclasses must define the DOCUMENT_TYPE constant # and the factory method. # # @example @@ -27,7 +27,7 @@ module OpenNebula # module OpenNebula # class CustomObjectPool < DocumentPool # - # DocumentPool::TYPE = 400 + # DOCUMENT_TYPE = 400 # # def factory(element_xml) # OpenNebula::CustomObject.new(element_xml, @client) @@ -72,22 +72,26 @@ module OpenNebula def info(*args) case args.size when 0 - info_filter(DOCUMENT_POOL_METHODS[:info],@user_id,-1,-1, TYPE) + info_filter(DOCUMENT_POOL_METHODS[:info],@user_id,-1,-1, document_type) when 3 - info_filter(DOCUMENT_POOL_METHODS[:info],args[0],args[1],args[2], TYPE) + info_filter(DOCUMENT_POOL_METHODS[:info],args[0],args[1],args[2], document_type) end end def info_all() - return super(DOCUMENT_POOL_METHODS[:info], TYPE) + return super(DOCUMENT_POOL_METHODS[:info], document_type) end def info_mine() - return super(DOCUMENT_POOL_METHODS[:info], TYPE) + return super(DOCUMENT_POOL_METHODS[:info], document_type) end def info_group() - return super(DOCUMENT_POOL_METHODS[:info], TYPE) + return super(DOCUMENT_POOL_METHODS[:info], document_type) + end + + def document_type + self.class::DOCUMENT_TYPE end end end