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' } } }.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
readonly
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.
-
#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.
99 100 101 102 103 104 |
# File 'lib/app_archetype/template/manifest.rb', line 99 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.
88 89 90 |
# File 'lib/app_archetype/template/manifest.rb', line 88 def data @data end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
88 89 90 |
# File 'lib/app_archetype/template/manifest.rb', line 88 def path @path end |
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
88 89 90 |
# File 'lib/app_archetype/template/manifest.rb', line 88 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.
79 80 81 82 83 84 85 |
# File 'lib/app_archetype/template/manifest.rb', line 79 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.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/app_archetype/template/manifest.rb', line 52 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
129 130 131 |
# File 'lib/app_archetype/template/manifest.rb', line 129 def @data. end |
#name ⇒ String
Manifest name getter
111 112 113 |
# File 'lib/app_archetype/template/manifest.rb', line 111 def name @data.name end |
#parent_path ⇒ String
Parent path of the manifest (working directory)
137 138 139 |
# File 'lib/app_archetype/template/manifest.rb', line 137 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.
161 162 163 164 165 166 167 168 |
# File 'lib/app_archetype/template/manifest.rb', line 161 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
146 147 148 |
# File 'lib/app_archetype/template/manifest.rb', line 146 def template_path File.join(parent_path, 'template') end |
#valid? ⇒ Boolean
Returns true if manifest is valid
188 189 190 |
# File 'lib/app_archetype/template/manifest.rb', line 188 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.
175 176 177 178 179 180 181 |
# File 'lib/app_archetype/template/manifest.rb', line 175 def validate JSON::Validator.fully_validate( SCHEMA, @data.to_h.to_json, strict: true ) end |
#version ⇒ String
Manifest version getter
120 121 122 |
# File 'lib/app_archetype/template/manifest.rb', line 120 def version @data.version end |