class AppArchetype::Template::Manifest

Manifest is a description of an archetype

Constants

MIN_ARCHETYPE_VERSION

Minimum supported archetype version

SCHEMA

Manifest JSON schema

Attributes

data[R]
path[R]
variables[R]

Public Class Methods

incompatible?(manifest) click to toggle source

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.

@param [Hash] manifest

@return [Boolean]

# 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(path, data) click to toggle source

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.

@param [String] path @param [Hash] data

# 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
new_from_file(file_path) click to toggle source

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

@param [String] file_path

# 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

Public Instance Methods

metadata() click to toggle source

Manifest metadata getter

@return [String]

# File lib/app_archetype/template/manifest.rb, line 129
def metadata
  @data.metadata
end
name() click to toggle source

Manifest name getter

@return [String]

# File lib/app_archetype/template/manifest.rb, line 111
def name
  @data.name
end
parent_path() click to toggle source

Parent path of the manifest (working directory)

@return [String]

# File lib/app_archetype/template/manifest.rb, line 137
def parent_path
  File.dirname(@path)
end
template() click to toggle 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.

@return [AppArchetype::Template::Source]

# 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() click to toggle source

Template files path

@return [String]

# File lib/app_archetype/template/manifest.rb, line 146
def template_path
  File.join(parent_path, 'template')
end
valid?() click to toggle source

Returns true if manifest is valid

@return [Boolean]

# File lib/app_archetype/template/manifest.rb, line 188
def valid?
  validate.empty?
end
validate() click to toggle source

Runs a schema validation on the given manifest to determine whether the schema is valid. Returns an array of validation messages.

@return [Array]

# 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() click to toggle source

Manifest version getter

@return [String]

# File lib/app_archetype/template/manifest.rb, line 120
def version
  @data.version
end