class Vara::Materials
Attributes
Public Class Methods
@param product_metadata_path [String] Path to a product's metadata file.
Expected to be in metadata/ folder of a product repo.
@param product_path [String] Path to a built .pivotal file on disk @return [Vara::Materials]
# File lib/vara/materials.rb, line 22 def self.build(product_metadata_path, product_path) product_metadata_dir = File.dirname(File.expand_path(product_metadata_path)) repo_dir = File.expand_path(File.join(product_metadata_dir, '..')) repo_name = File.basename(repo_dir) product_metadata = ProductMetadata.from_file(product_metadata_path) repo_revision = if GitInspector.git_repo?(repo_dir) GitInspector.new(repo_dir).current_revision else log.warn('Creating Materials from a non-git repository') 'not_a_git_repository' end materials_hash = { 'filename' => File.basename(product_path), 'md5' => Digest::MD5.file(product_path).hexdigest, 'contents' => { 'releases' => product_metadata.releases_metadata.map(&:basename), 'compiled_packages' => [] }, 'build_info' => { 'product_repository' => repo_name, 'product_revision' => repo_revision, 'vara_version' => Vara::VERSION } } if product_metadata.explicit_stemcell? materials_hash['contents']['stemcells'] = [product_metadata.stemcell_metadata.basename] if product_metadata.has_compiled_packages? materials_hash['contents']['compiled_packages'] << product_metadata.compiled_packages_metadata.basename end else materials_hash['contents']['stemcell_criteria'] = product_metadata.stemcell_criteria end new(materials_hash) end
@param materials_path [String] Path to a materials YAML file @return [Vara::Materials] A Materials
object based on the content of the file at materials_path
# File lib/vara/materials.rb, line 14 def self.from_file(materials_path) new(YAML.load_file(materials_path)) end
@param materials_hash [Hash]
# File lib/vara/materials.rb, line 64 def initialize(materials_hash) @hash = materials_hash end
Public Instance Methods
@return [<String>] The listed compiled packages contained in the .pivotal file
# File lib/vara/materials.rb, line 97 def compiled_packages contents.fetch('compiled_packages') end
@return [String] The filename of the .pivotal file
# File lib/vara/materials.rb, line 73 def filename hash.fetch('filename') end
@return [String] The listed md5 of the .pivotal file
# File lib/vara/materials.rb, line 78 def md5 hash.fetch('md5') end
@return [String] The name of the product repository
# File lib/vara/materials.rb, line 102 def product_repository build_info.fetch('product_repository') end
@return [String] The git revision of the product repository used to build the .pivotal
# File lib/vara/materials.rb, line 107 def product_revision build_info.fetch('product_revision') end
@return [<String>] The listed releases contained in the .pivotal file
# File lib/vara/materials.rb, line 83 def releases contents.fetch('releases') end
# File lib/vara/materials.rb, line 68 def save_to(file_path) File.open(file_path, 'w') { |file| YAML.dump(hash, file) } end
# File lib/vara/materials.rb, line 92 def stemcell_criteria contents['stemcell_criteria'] end
@return [<String>] The listed stemcells contained in the .pivotal file
# File lib/vara/materials.rb, line 88 def stemcells contents['stemcells'] end
@return [String] the version of vara used to build the described .pivotal (will be >= 0.7.1 or 'unknown')
# File lib/vara/materials.rb, line 112 def vara_version build_info.fetch('vara_version', 'unknown') end
Private Instance Methods
@return [Hash]
# File lib/vara/materials.rb, line 126 def build_info hash.fetch('build_info') end
@return [Hash]
# File lib/vara/materials.rb, line 121 def contents hash.fetch('contents') end