Class: Vara::Materials
- Inherits:
-
Object
- Object
- Vara::Materials
- Includes:
- Loggable
- Defined in:
- lib/vara/materials.rb
Class Method Summary collapse
- .build(product_metadata_path, product_path) ⇒ Vara::Materials
-
.from_file(materials_path) ⇒ Vara::Materials
A Materials object based on the content of the file at materials_path.
Instance Method Summary collapse
-
#compiled_packages ⇒ <String>
The listed compiled packages contained in the .pivotal file.
-
#filename ⇒ String
The filename of the .pivotal file.
-
#initialize(materials_hash) ⇒ Materials
constructor
A new instance of Materials.
-
#md5 ⇒ String
The listed md5 of the .pivotal file.
-
#product_repository ⇒ String
The name of the product repository.
-
#product_revision ⇒ String
The git revision of the product repository used to build the .pivotal.
-
#releases ⇒ <String>
The listed releases contained in the .pivotal file.
- #save_to(file_path) ⇒ Object
- #stemcell_criteria ⇒ Object
-
#stemcells ⇒ <String>
The listed stemcells contained in the .pivotal file.
-
#vara_version ⇒ String
The version of vara used to build the described .pivotal (will be >= 0.7.1 or ‘unknown’).
Methods included from Loggable
Constructor Details
#initialize(materials_hash) ⇒ Materials
Returns a new instance of Materials.
64 65 66 |
# File 'lib/vara/materials.rb', line 64 def initialize(materials_hash) @hash = materials_hash end |
Class Method Details
.build(product_metadata_path, product_path) ⇒ Vara::Materials
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 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 |
# File 'lib/vara/materials.rb', line 22 def self.build(, product_path) = File.dirname(File.()) repo_dir = File.(File.join(, '..')) repo_name = File.basename(repo_dir) = ProductMetadata.from_file() 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' => ..map(&:basename), 'compiled_packages' => [] }, 'build_info' => { 'product_repository' => repo_name, 'product_revision' => repo_revision, 'vara_version' => Vara::VERSION } } if .explicit_stemcell? materials_hash['contents']['stemcells'] = [..basename] if .has_compiled_packages? materials_hash['contents']['compiled_packages'] << ..basename end else materials_hash['contents']['stemcell_criteria'] = .stemcell_criteria end new(materials_hash) end |
.from_file(materials_path) ⇒ Vara::Materials
Returns A Materials object based on the content of the file at materials_path.
14 15 16 |
# File 'lib/vara/materials.rb', line 14 def self.from_file(materials_path) new(YAML.load_file(materials_path)) end |
Instance Method Details
#compiled_packages ⇒ <String>
Returns The listed compiled packages contained in the .pivotal file.
97 98 99 |
# File 'lib/vara/materials.rb', line 97 def compiled_packages contents.fetch('compiled_packages') end |
#filename ⇒ String
Returns The filename of the .pivotal file.
73 74 75 |
# File 'lib/vara/materials.rb', line 73 def filename hash.fetch('filename') end |
#md5 ⇒ String
Returns The listed md5 of the .pivotal file.
78 79 80 |
# File 'lib/vara/materials.rb', line 78 def md5 hash.fetch('md5') end |
#product_repository ⇒ String
Returns The name of the product repository.
102 103 104 |
# File 'lib/vara/materials.rb', line 102 def product_repository build_info.fetch('product_repository') end |
#product_revision ⇒ String
Returns The git revision of the product repository used to build the .pivotal.
107 108 109 |
# File 'lib/vara/materials.rb', line 107 def product_revision build_info.fetch('product_revision') end |
#releases ⇒ <String>
Returns The listed releases contained in the .pivotal file.
83 84 85 |
# File 'lib/vara/materials.rb', line 83 def releases contents.fetch('releases') end |
#save_to(file_path) ⇒ Object
68 69 70 |
# File 'lib/vara/materials.rb', line 68 def save_to(file_path) File.open(file_path, 'w') { |file| YAML.dump(hash, file) } end |
#stemcell_criteria ⇒ Object
92 93 94 |
# File 'lib/vara/materials.rb', line 92 def stemcell_criteria contents['stemcell_criteria'] end |
#stemcells ⇒ <String>
Returns The listed stemcells contained in the .pivotal file.
88 89 90 |
# File 'lib/vara/materials.rb', line 88 def stemcells contents['stemcells'] end |
#vara_version ⇒ String
Returns the version of vara used to build the described .pivotal (will be >= 0.7.1 or ‘unknown’).
112 113 114 |
# File 'lib/vara/materials.rb', line 112 def vara_version build_info.fetch('vara_version', 'unknown') end |