Class: Vara::ProductMetadata

Inherits:
Object
  • Object
show all
Defined in:
lib/vara/product_metadata.rb

Overview

“Struct” representing the information in metadata/<product_name>.yml

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ ProductMetadata

Returns a new instance of ProductMetadata.

Parameters:

  • hash (Hash)

    the hash representing the product metadata



20
21
22
# File 'lib/vara/product_metadata.rb', line 20

def initialize(hash)
  @hash = hash
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



10
11
12
# File 'lib/vara/product_metadata.rb', line 10

def hash
  @hash
end

Class Method Details

.from_file(metadata_path) ⇒ Vara::ProductMetadata

Build a ProductMetadata from a metadata.yml on disk

Parameters:

  • metadata_path

    Path to the product metadata file on disk

Returns:



15
16
17
# File 'lib/vara/product_metadata.rb', line 15

def self.from_file()
  new(YAML.load_file())
end

Instance Method Details

#compiled_packages_fileString

Returns the filename of the compiled packages.

Returns:

  • (String)

    the filename of the compiled packages



80
81
82
# File 'lib/vara/product_metadata.rb', line 80

def compiled_packages_file
  .basename
end

#compiled_packages_metadataVara::Metadata::CompiledPackages

Returns the compiled packages metadata contained in this ProductMetadata.

Returns:

Raises:

  • (KeyNotFoundError)

    if this ProductMetadata does not contain compiled packages



57
58
59
60
61
62
# File 'lib/vara/product_metadata.rb', line 57

def 
  c = hash.fetch('compiled_package')
  Metadata::CompiledPackages.new(
    c.fetch('name'), c.fetch('version'), c.fetch('file'), c.fetch('md5'), c.fetch('url', nil)
  )
end

#explicit_stemcell?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/vara/product_metadata.rb', line 24

def explicit_stemcell?
  hash.key? 'stemcell'
end

#has_compiled_packages?Boolean

Returns whether the compiled packages field is present.

Returns:

  • (Boolean)

    whether the compiled packages field is present



85
86
87
# File 'lib/vara/product_metadata.rb', line 85

def has_compiled_packages?
  hash.key?('compiled_package')
end

#nameString

Returns the name of the product.

Returns:

  • (String)

    the name of the product



70
71
72
# File 'lib/vara/product_metadata.rb', line 70

def name
  hash.fetch('name')
end

#product_versionString

Returns the version of the product.

Returns:

  • (String)

    the version of the product



75
76
77
# File 'lib/vara/product_metadata.rb', line 75

def product_version
  hash.fetch('product_version')
end

#releases_metadata<Vara::Metadata::Release>

Returns the releases metadata contained in this ProductMetadata.

Returns:



50
51
52
53
# File 'lib/vara/product_metadata.rb', line 50

def 
  releases = hash.fetch('releases')
  releases.map { |release| (release) }
end

#stemcell_criteriaObject



28
29
30
31
# File 'lib/vara/product_metadata.rb', line 28

def stemcell_criteria
  return nil if explicit_stemcell?
  hash.fetch('stemcell_criteria')
end

#stemcell_criteria?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/vara/product_metadata.rb', line 33

def stemcell_criteria?
  hash.key? 'stemcell_criteria'
end

#stemcell_fileString

Returns the filename of the stemcell.

Returns:

  • (String)

    the filename of the stemcell



65
66
67
# File 'lib/vara/product_metadata.rb', line 65

def stemcell_file
  .basename
end

#stemcell_metadataVara::Metadata::Stemcell

Returns the stemcell metadata contained in this ProductMetadata.

Returns:



38
39
40
41
42
43
44
45
46
47
# File 'lib/vara/product_metadata.rb', line 38

def 
  stemcell = hash.fetch('stemcell')
  Metadata::Stemcell.new(
    name: stemcell.fetch('name'),
    version: stemcell.fetch('version'),
    file: stemcell.fetch('file'),
    md5: stemcell.fetch('md5', nil),
    sha1: stemcell.fetch('sha1', nil)
  )
end