Class: GeneSystem::Manifest
- Inherits:
-
Object
- Object
- GeneSystem::Manifest
- 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
-
.incompatible?(manifest) ⇒ Boolean
Incompatible returns true if the current manifest is not compatible with this version of GeneSystem.
-
.missing_required?(manifest) ⇒ Boolean
Determines whether there are missing attributes in given manifest.
-
.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.
Instance Method Summary collapse
-
#initialize(path, data) ⇒ Manifest
constructor
A new instance of Manifest.
-
#metadata ⇒ Object
Manifest metadata getter.
-
#name ⇒ String
Manifest name getter.
-
#name_and_version ⇒ String
Manifest name and version getter.
-
#platform ⇒ Object
Platform metadata getter.
-
#steps ⇒ GeneSystem::StepCollection
Returns a steps as a step collection.
-
#variables ⇒ Hashie::Mash
Returns manifest information and variables.
-
#version ⇒ String
Manifest version getter.
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.
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
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.
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
#metadata ⇒ Object
Manifest metadata getter
125 126 127 |
# File 'lib/gene_system/manifest.rb', line 125 def @data. end |
#name ⇒ String
Manifest name getter
107 108 109 |
# File 'lib/gene_system/manifest.rb', line 107 def name @data.name end |
#name_and_version ⇒ String
Manifest name and version getter
98 99 100 |
# File 'lib/gene_system/manifest.rb', line 98 def name_and_version "#{name} v#{version}" end |
#platform ⇒ Object
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 |
#steps ⇒ GeneSystem::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 |
#variables ⇒ Hashie::Mash
Returns manifest information and variables
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 |
#version ⇒ String
Manifest version getter
116 117 118 |
# File 'lib/gene_system/manifest.rb', line 116 def version @data.version end |