Class: FileMetadata
Constant Summary
Constants inherited from Metadata
Instance Attribute Summary
Attributes inherited from Metadata
#file, #format, #source, #text
Class Method Summary collapse
-
.instantiate_from_dir(dir) ⇒ Object
Given the directory from which the file_metadata is saved, returns a FileMetadata object.
Instance Method Summary collapse
Methods inherited from Metadata
#[], #[]=, #add_tpkg_version, clean_for_filename, #generate_package_filename, #get_native_deps, get_pkgs_metadata_from_yml_doc, #initialize, #metadata_xml_to_hash, #validate, #verify_required_fields, #verify_yaml, #write
Constructor Details
This class inherits a constructor from Metadata
Class Method Details
.instantiate_from_dir(dir) ⇒ Object
Given the directory from which the file_metadata is saved, returns a FileMetadata object. The file_metadata file can be in binary, yaml or xml.
737 738 739 740 741 742 743 744 745 746 747 |
# File 'lib/tpkg/metadata.rb', line 737 def self.instantiate_from_dir(dir) = nil if File.exist?(File.join(dir, 'file_metadata.bin')) = FileMetadata.new(File.read(File.join(dir, 'file_metadata.bin')), 'bin') elsif File.exist?(File.join(dir, 'file_metadata.yml')) = FileMetadata.new(File.read(File.join(dir, 'file_metadata.yml')), 'yml') elsif File.exists?(File.join(dir, 'file_metadata.xml')) = FileMetadata.new(File.read(File.join(dir, 'file_metadata.xml')), 'xml') end return end |
Instance Method Details
#file_metadata_xml_to_hash ⇒ Object
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 |
# File 'lib/tpkg/metadata.rb', line 766 def return if @format != "xml" = {} files = [] = REXML::Document.new(@text) [:package_file] = .root.attributes['package_file'] .elements.each("files/file") do | file_ele | file = {} file[:path] = file_ele.elements['path'].text file[:relocatable] = file_ele.attributes["relocatable"] == "true" if file_ele.elements["checksum"] digests = [] file_ele.elements.each("checksum/digest") do | digest_ele | digest = {} digest['value'] = digest_ele.text digest['encrypted'] = digest_ele.attributes['encrypted'] && digest_ele.attributes['encrypted'] == "true" digest['decrypted'] = digest_ele.attributes['decrypted'] && digest_ele.attributes['decrypted'] == "true" digests << digest end checksum = {:digests => digests, :algorithm => file_ele.elements["checksum"].elements["algorithm"]} end file[:checksum] = checksum files << file end [:files] = files return end |
#to_hash ⇒ Object
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 |
# File 'lib/tpkg/metadata.rb', line 749 def to_hash if @hash return @hash end if @format == 'bin' hash = Marshal::load(@text) @hash = hash.with_indifferent_access elsif @format == 'yml' hash = YAML::load(@text) @hash = hash.with_indifferent_access elsif @format == 'xml' @hash = end return @hash end |