Class: Deliver::MetadataItem
- Inherits:
-
Object
- Object
- Deliver::MetadataItem
- Defined in:
- lib/deliver/metadata_item.rb
Overview
This class represents a file, included in the metadata.xml
It takes care of calculating the file size and md5 value.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#path ⇒ String
The path to this particular asset.
Instance Method Summary collapse
-
#create_xml_node(doc) ⇒ Nokogiri::XML::Node
This method is called when storing this item into the metadata.xml file.
-
#initialize(path, custom_node_name = nil) ⇒ MetadataItem
constructor
Returns a new instance of MetadataItem.
-
#store_file_inside_package(path_to_package) ⇒ Object
We also have to copy the file itself, since it has to be inside the package You don’t have to call this method manually.
Constructor Details
#initialize(path, custom_node_name = nil) ⇒ MetadataItem
Returns a new instance of MetadataItem
15 16 17 18 19 20 |
# File 'lib/deliver/metadata_item.rb', line 15 def initialize(path, custom_node_name = nil) raise "File not found at path '#{path}'" unless File.exists?path self.path = path @custom_node_name = custom_node_name end |
Instance Attribute Details
#path ⇒ String
Returns The path to this particular asset.
9 10 11 |
# File 'lib/deliver/metadata_item.rb', line 9 def path @path end |
Instance Method Details
#create_xml_node(doc) ⇒ Nokogiri::XML::Node
This method is called when storing this item into the metadata.xml file
This method will calculate the md5 hash and exact file size Generates XML code that looks something like this code
<data_file>
<size>11463227</size>
<file_name>myapp.54.56.ipa</file_name>
<checksum type="md5">9d6b7b0e20bde9a3c831db89563e949f</checksum>
</data_file>
Take a look at the subclass AppScreenshot#create_xml_node for a screenshot specific implementation
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/deliver/metadata_item.rb', line 37 def create_xml_node(doc) screenshot = Nokogiri::XML::Node.new(name_for_xml_node, doc) node_set = Nokogiri::XML::NodeSet.new(doc) # File Size size = Nokogiri::XML::Node.new('size', doc) size.content = File.size(self.path) node_set << size # File Name file_name = Nokogiri::XML::Node.new('file_name', doc) file_name.content = resulting_file_name node_set << file_name # md5 Checksum checksum = Nokogiri::XML::Node.new('checksum', doc) checksum.content = md5_value checksum['type'] = 'md5' node_set << checksum screenshot.children = node_set return screenshot end |
#store_file_inside_package(path_to_package) ⇒ Object
We also have to copy the file itself, since it has to be inside the package You don’t have to call this method manually.
66 67 68 69 70 71 |
# File 'lib/deliver/metadata_item.rb', line 66 def store_file_inside_package(path_to_package) # This will also rename the resulting file to not have any spaces or other # illegal characters in the file name FileUtils.cp(self.path, "#{path_to_package}/#{resulting_file_name}") end |