Class: GeneSystem::Manifest

Inherits:
Object
  • Object
show all
Defined in:
lib/gene_system/manifest.rb

Overview

Manifest is an in memory representation of a manifest file

Constant Summary collapse

DEFAULT_QUERY =
->(_step) { return true }
SUPPORTED_PLATFORMS =

list of supported platforms

%w[macos debian].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, data) ⇒ Manifest

Returns a new instance of Manifest.



87
88
89
90
91
# File 'lib/gene_system/manifest.rb', line 87

def initialize(path, data)
  @path = path
  @data = Hashie::Mash.new(data)
  @steps = GeneSystem::Step.load_steps(@data.steps)
end

Class Method Details

.incompatible?(manifest) ⇒ Boolean

Incompatible returns true if the current manifest is not compatible with this version of GeneSystem.

A manifest is not compatible if it was created with a version greater than this the installed version.

Parameters:

  • manifest (Hash)

Returns:

  • (Boolean)


76
77
78
79
80
81
# File 'lib/gene_system/manifest.rb', line 76

def incompatible?(manifest)
  manifest_version = manifest['metadata']['gene_system']['version']
  manifest_version > GeneSystem::VERSION
rescue NoMethodError
  true
end

.missing_required?(manifest) ⇒ Boolean

Determines whether there are missing attributes in given manifest.

Manifests require name, version and metadata attributes.

If these are not present in the given manifest then this method returns true, indicating that the manifest does not have all required attributes and is therefore not valid.

If they are present, then false will be returned indicating that the manifest has required attributes

Parameters:

Returns:

  • (Boolean)


57
58
59
60
61
62
63
# File 'lib/gene_system/manifest.rb', line 57

def missing_required?(manifest)
  return true unless manifest['name']
  return true unless manifest['version']
  return true unless manifest['metadata']

  false
end

.new_from_file(file_path) ⇒ Object

Creates a [GeneSystem::Manifest] from a manifest json so long as the manifest is compatible with this version of GeneSystem.

Parameters:

  • file_path (String)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gene_system/manifest.rb', line 16

def new_from_file(file_path)
  manifest = Jsonnet.evaluate(
    File.read(file_path)
  )

  if missing_required?(manifest)
    raise 'manifest is missing required attributes name, '\
    'version and/or metadata'
  end

  if incompatible?(manifest)
    raise 'provided manifest is invalid or incompatible with '\
    'this version of gene_system'
  end

  new(
    file_path,
    manifest
  )
end

Instance Method Details

#metadataObject

Manifest metadata getter

@return



125
126
127
# File 'lib/gene_system/manifest.rb', line 125

def 
  @data.
end

#nameString

Manifest name getter

Returns:

  • (String)


107
108
109
# File 'lib/gene_system/manifest.rb', line 107

def name
  @data.name
end

#name_and_versionString

Manifest name and version getter

Returns:

  • (String)


98
99
100
# File 'lib/gene_system/manifest.rb', line 98

def name_and_version
  "#{name} v#{version}"
end

#platformObject

Platform metadata getter

Prints a warning when the platform is not recognized

@return



136
137
138
139
140
141
142
# File 'lib/gene_system/manifest.rb', line 136

def platform
  platform = @data.platform

  CLI.print_warning("WARN: unrecognized platform: #{@data.platform}") unless SUPPORTED_PLATFORMS.include?(platform)

  platform
end

#stepsGeneSystem::StepCollection

Returns a steps as a step collection



149
150
151
# File 'lib/gene_system/manifest.rb', line 149

def steps
  GeneSystem::StepCollection.new(@steps)
end

#variablesHashie::Mash

Returns manifest information and variables

Returns:

  • (Hashie::Mash)


158
159
160
161
162
163
164
165
166
# File 'lib/gene_system/manifest.rb', line 158

def variables
  Hashie::Mash.new(
    'manifest' => {
      'name' => name,
      'version' => version,
      'metadata' => 
    }
  )
end

#versionString

Manifest version getter

Returns:

  • (String)


116
117
118
# File 'lib/gene_system/manifest.rb', line 116

def version
  @data.version
end