Class: Vara::Materials

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/vara/materials.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Loggable

included, #log

Constructor Details

#initialize(materials_hash) ⇒ Materials

Returns a new instance of Materials.

Parameters:

  • materials_hash (Hash)


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

Parameters:

  • product_metadata_path (String)

    Path to a product’s metadata file. Expected to be in metadata/ folder of a product repo.

  • product_path (String)

    Path to a built .pivotal file on disk

Returns:



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.expand_path())
  repo_dir = File.expand_path(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.

Parameters:

  • materials_path (String)

    Path to a materials YAML file

Returns:

  • (Vara::Materials)

    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.

Returns:

  • (<String>)

    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

#filenameString

Returns The filename of the .pivotal file.

Returns:

  • (String)

    The filename of the .pivotal file



73
74
75
# File 'lib/vara/materials.rb', line 73

def filename
  hash.fetch('filename')
end

#md5String

Returns The listed md5 of the .pivotal file.

Returns:

  • (String)

    The listed md5 of the .pivotal file



78
79
80
# File 'lib/vara/materials.rb', line 78

def md5
  hash.fetch('md5')
end

#product_repositoryString

Returns The name of the product repository.

Returns:

  • (String)

    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_revisionString

Returns The git revision of the product repository used to build the .pivotal.

Returns:

  • (String)

    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.

Returns:

  • (<String>)

    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_criteriaObject



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.

Returns:

  • (<String>)

    The listed stemcells contained in the .pivotal file



88
89
90
# File 'lib/vara/materials.rb', line 88

def stemcells
  contents['stemcells']
end

#vara_versionString

Returns the version of vara used to build the described .pivotal (will be >= 0.7.1 or ‘unknown’).

Returns:

  • (String)

    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