Class: Metaforce::Manifest
- Inherits:
-
Hash
- Object
- Hash
- Metaforce::Manifest
- Defined in:
- lib/metaforce/manifest.rb
Instance Method Summary collapse
-
#initialize(components = {}) ⇒ Manifest
constructor
Public: Initializes a new instance of a manifest (package.xml) file.
-
#parse(file) ⇒ Object
Public: Parses a package.xml file.
-
#to_package ⇒ Object
Public: Converts the manifest into a format that can be used by the metadata api.
-
#to_xml ⇒ Object
Public: Returns a string containing a package.xml file.
Constructor Details
#initialize(components = {}) ⇒ Manifest
Public: Initializes a new instance of a manifest (package.xml) file.
It can either take a hash:
{
:apex_class => [
"TestController",
"TestClass"
],
:apex_component => [
"SiteLogin"
]
}
Or an xml string containing the contents of a packge.xml file:
<?xml version="1.0"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>TestClass</members>
<members>AnotherClass</members>
<name>ApexClass</name>
</types>
<types>
<members>Component</members>
<name>ApexComponent</name>
</types>
<types>
<members>Assets</members>
<name>StaticResource</name>
</types>
<version>23.0</version>
</Package>
39 40 41 42 43 44 45 46 |
# File 'lib/metaforce/manifest.rb', line 39 def initialize(components={}) self.replace Hash.new { |h,k| h[k] = [] } if components.is_a?(Hash) self.merge!(components) elsif components.is_a?(String) self.parse(components) end end |
Instance Method Details
#parse(file) ⇒ Object
Public: Parses a package.xml file
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/metaforce/manifest.rb', line 93 def parse(file) document = Nokogiri::XML(file).remove_namespaces! document.xpath('//types').each do |type| name = type.xpath('name').first.content key = name.underscore.to_sym type.xpath('members').each do |member| self[key] << member.content end end self end |
#to_package ⇒ Object
Public: Converts the manifest into a format that can be used by the metadata api.
86 87 88 89 90 |
# File 'lib/metaforce/manifest.rb', line 86 def to_package self.map do |type, members| { :members => members, :name => type.to_s.camelize } end end |
#to_xml ⇒ Object
Public: Returns a string containing a package.xml file
<?xml version="1.0"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>TestClass</members>
<members>AnotherClass</members>
<name>ApexClass</name>
</types>
<types>
<members>Component</members>
<name>ApexComponent</name>
</types>
<types>
<members>Assets</members>
<name>StaticResource</name>
</types>
<version>23.0</version>
</Package>
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/metaforce/manifest.rb', line 67 def to_xml xml_builder = Nokogiri::XML::Builder.new do |xml| xml.Package('xmlns' => 'http://soap.sforce.com/2006/04/metadata') { self.each do |key, members| xml.types { members.each do |member| xml.members member end xml.name key.to_s.camelize } end xml.version Metaforce.configuration.api_version } end xml_builder.to_xml end |