Class: AppArchetype::Template::Manifest
- Inherits:
-
Object
- Object
- AppArchetype::Template::Manifest
- Defined in:
- lib/app_archetype/template/manifest.rb
Overview
Manifest is a description of an archetype
Constant Summary collapse
- MIN_ARCHETYPE_VERSION =
Minimum supported archetype version
'1.0.0'.freeze
- SCHEMA =
Manifest JSON schema
{ type: 'object', required: %w[name version metadata variables], properties: { name: { type: 'string' }, version: { type: 'string' }, metadata: { type: 'object', required: %w[app_archetype], properties: { app_archetype: { type: 'object', required: %w[version] } } }, variables: { type: 'object' }, next_steps: { type: 'array' } } }.freeze
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#variables ⇒ Object
Returns the value of attribute variables.
Class Method Summary collapse
-
.incompatible?(manifest) ⇒ Boolean
Incompatible returns true if the current manifest is not compatible with this version of AppArchetype.
-
.new_from_file(file_path) ⇒ Object
Creates a [AppArchetype::Template] from a manifest json so long as the manifest is compatible with this version of AppArchetype.
Instance Method Summary collapse
-
#initialize(path, data) ⇒ Manifest
constructor
Creates a manifest and memoizes the manifest data hash as a Hashe::Map.
-
#metadata ⇒ String
Manifest metadata getter.
-
#name ⇒ String
Manifest name getter.
-
#next_steps ⇒ String
Next steps getter.
-
#parent_path ⇒ String
Parent path of the manifest (working directory).
-
#template ⇒ AppArchetype::Template::Source
Loads the template that is adjacent to the manifest.json or manifest.jsonnet file.
-
#template_path ⇒ String
Template files path.
-
#valid? ⇒ Boolean
Returns true if manifest is valid.
-
#validate ⇒ Array
Runs a schema validation on the given manifest to determine whether the schema is valid.
-
#version ⇒ String
Manifest version getter.
Constructor Details
#initialize(path, data) ⇒ Manifest
Creates a manifest and memoizes the manifest data hash as a Hashe::Map
On initialize the manifest variables are retrieved and memoized for use in rendering the templates.
102 103 104 105 106 107 |
# File 'lib/app_archetype/template/manifest.rb', line 102 def initialize(path, data) @path = path @data = OpenStruct.new(data) @variables = AppArchetype::Template::VariableManager .new(@data.variables) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
91 92 93 |
# File 'lib/app_archetype/template/manifest.rb', line 91 def data @data end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
91 92 93 |
# File 'lib/app_archetype/template/manifest.rb', line 91 def path @path end |
#variables ⇒ Object
Returns the value of attribute variables.
91 92 93 |
# File 'lib/app_archetype/template/manifest.rb', line 91 def variables @variables end |
Class Method Details
.incompatible?(manifest) ⇒ Boolean
Incompatible returns true if the current manifest is not compatible with this version of AppArchetype.
A manifest is not compatible if it was created with a version greater than this the installed version.
82 83 84 85 86 87 88 |
# File 'lib/app_archetype/template/manifest.rb', line 82 def incompatible?(manifest) manifest_version = manifest['metadata']['app_archetype']['version'] return true if manifest_version < MIN_ARCHETYPE_VERSION return true if manifest_version > AppArchetype::VERSION rescue NoMethodError true end |
.new_from_file(file_path) ⇒ Object
Creates a [AppArchetype::Template] from a manifest json so long as the manifest is compatible with this version of AppArchetype.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/app_archetype/template/manifest.rb', line 55 def new_from_file(file_path) manifest = Jsonnet.evaluate( File.read(file_path) ) if incompatible?(manifest) raise 'provided manifest is invalid or incompatible with '\ 'this version of app archetype' end new( file_path, manifest ) end |
Instance Method Details
#metadata ⇒ String
Manifest metadata getter
132 133 134 |
# File 'lib/app_archetype/template/manifest.rb', line 132 def @data. end |
#name ⇒ String
Manifest name getter
114 115 116 |
# File 'lib/app_archetype/template/manifest.rb', line 114 def name @data.name end |
#next_steps ⇒ String
Next steps getter
141 142 143 144 145 146 147 |
# File 'lib/app_archetype/template/manifest.rb', line 141 def next_steps steps = @data.next_steps return [] unless steps steps end |
#parent_path ⇒ String
Parent path of the manifest (working directory)
153 154 155 |
# File 'lib/app_archetype/template/manifest.rb', line 153 def parent_path File.dirname(@path) end |
#template ⇒ AppArchetype::Template::Source
Loads the template that is adjacent to the manifest.json or manifest.jsonnet file.
If the template cannot be found, a RuntimeError explaining that the template cannot be found is raised.
Loaded template is memoized for the current session.
177 178 179 180 181 182 183 184 |
# File 'lib/app_archetype/template/manifest.rb', line 177 def template unless File.exist?(template_path) raise "cannot find template for manifest #{name}" end @template ||= AppArchetype::Template::Source.new(template_path) @template end |
#template_path ⇒ String
Template files path
162 163 164 |
# File 'lib/app_archetype/template/manifest.rb', line 162 def template_path File.join(parent_path, 'template') end |
#valid? ⇒ Boolean
Returns true if manifest is valid
204 205 206 |
# File 'lib/app_archetype/template/manifest.rb', line 204 def valid? validate.empty? end |
#validate ⇒ Array
Runs a schema validation on the given manifest to determine whether the schema is valid. Returns an array of validation messages.
191 192 193 194 195 196 197 |
# File 'lib/app_archetype/template/manifest.rb', line 191 def validate JSON::Validator.fully_validate( SCHEMA, @data.to_h.to_json, strict: true ) end |
#version ⇒ String
Manifest version getter
123 124 125 |
# File 'lib/app_archetype/template/manifest.rb', line 123 def version @data.version end |