Class: OpenNebula::DocumentPoolJSON
- Inherits:
-
DocumentPool
- Object
- XMLElement
- XMLPool
- Pool
- DocumentPool
- OpenNebula::DocumentPoolJSON
- Defined in:
- lib/opennebula/document_pool_json.rb
Direct Known Subclasses
Constant Summary collapse
- TEMPLATE_TAG =
"BODY"
Constants inherited from DocumentPool
OpenNebula::DocumentPool::DOCUMENT_POOL_METHODS
Constants inherited from Pool
Pool::INFO_ALL, Pool::INFO_GROUP, Pool::INFO_MINE, Pool::INFO_PRIMARY_GROUP, Pool::PAGINATED_POOLS
Instance Attribute Summary
Attributes inherited from Pool
Instance Method Summary collapse
- #factory(element_xml) ⇒ Object
-
#to_json(pretty_generate = true) ⇒ String
Generates a json representing the object.
Methods inherited from DocumentPool
#document_type, #info, #info_all, #info_group, #info_mine, #initialize
Methods inherited from Pool
#each, #each_page, #each_page_delete, #each_with_xpath, #get_hash, #get_page, #info_paginated, #is_paginated?, #loop_page, #to_str
Methods inherited from XMLPool
Methods inherited from XMLElement
#[], #add_element, #attr, build_xml, #delete_element, #each, #each_xpath, #element_xml, #has_elements?, #initialize, #initialize_xml, #name, #retrieve_elements, #retrieve_xmlelements, #set_content, #template_like_str, #template_str, #template_xml, #text, #to_hash, #to_xml, #xml_nil?
Constructor Details
This class inherits a constructor from OpenNebula::DocumentPool
Instance Method Details
#factory(element_xml) ⇒ Object
22 23 24 25 26 |
# File 'lib/opennebula/document_pool_json.rb', line 22 def factory(element_xml) doc = OpenNebula::DocumentJSON.new(element_xml, @client) doc.load_body doc end |
#to_json(pretty_generate = true) ⇒ String
Generates a json representing the object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/opennebula/document_pool_json.rb', line 33 def to_json(pretty_generate=true) hash = self.to_hash if hash['DOCUMENT_POOL'] && hash['DOCUMENT_POOL']['DOCUMENT'] if !hash['DOCUMENT_POOL']['DOCUMENT'].instance_of?(Array) array = [hash['DOCUMENT_POOL']['DOCUMENT']] hash['DOCUMENT_POOL']['DOCUMENT'] = array.compact end hash['DOCUMENT_POOL']['DOCUMENT'].each { |doc| body = doc['TEMPLATE']["#{TEMPLATE_TAG}"] if body && !body.empty? b_hash = JSON.parse(body) doc['TEMPLATE']["#{TEMPLATE_TAG}"] = b_hash end } end if pretty_generate JSON.pretty_generate hash else hash.to_json end end |