Class: Arrolio::Flavor::Manifest
- Inherits:
-
Object
- Object
- Arrolio::Flavor::Manifest
- Defined in:
- lib/arrolio/flavor/manifest.rb
Overview
Typed view over a flavor's manifest.yml. Declares the flavor's
name, version, upstream XSL, required/optional fonts, and the
paths to its three config files. Validates the manifest at load
time so broken flavors fail loudly with Arrolio::FlavorError.
Constant Summary collapse
- REQUIRED_FIELDS =
['name', 'version', 'config_files'].freeze
Instance Attribute Summary collapse
-
#config_files ⇒ Object
readonly
Returns the value of attribute config_files.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#doctypes ⇒ Object
readonly
Returns the value of attribute doctypes.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#optional_fonts ⇒ Object
readonly
Returns the value of attribute optional_fonts.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#required_fonts ⇒ Object
readonly
Returns the value of attribute required_fonts.
-
#upstream ⇒ Object
readonly
Returns the value of attribute upstream.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #config_path_for(role, flavor_dir = File.dirname(@path)) ⇒ Object
- #hash ⇒ Object
-
#initialize(path, data) ⇒ Manifest
constructor
A new instance of Manifest.
Constructor Details
#initialize(path, data) ⇒ Manifest
Returns a new instance of Manifest.
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/arrolio/flavor/manifest.rb', line 42 def initialize(path, data) @path = path @name = data.fetch('name') @version = data.fetch('version') @description = data['description'] @upstream = data['upstream'] || {} @doctypes = data['doctypes'] || [] fonts = data['fonts'] || {} @required_fonts = fonts['required'] || [] @optional_fonts = fonts['optional'] || [] @config_files = data.fetch('config_files') freeze end |
Instance Attribute Details
#config_files ⇒ Object (readonly)
Returns the value of attribute config_files.
15 16 17 |
# File 'lib/arrolio/flavor/manifest.rb', line 15 def config_files @config_files end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
15 16 17 |
# File 'lib/arrolio/flavor/manifest.rb', line 15 def description @description end |
#doctypes ⇒ Object (readonly)
Returns the value of attribute doctypes.
15 16 17 |
# File 'lib/arrolio/flavor/manifest.rb', line 15 def doctypes @doctypes end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/arrolio/flavor/manifest.rb', line 15 def name @name end |
#optional_fonts ⇒ Object (readonly)
Returns the value of attribute optional_fonts.
15 16 17 |
# File 'lib/arrolio/flavor/manifest.rb', line 15 def optional_fonts @optional_fonts end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
15 16 17 |
# File 'lib/arrolio/flavor/manifest.rb', line 15 def path @path end |
#required_fonts ⇒ Object (readonly)
Returns the value of attribute required_fonts.
15 16 17 |
# File 'lib/arrolio/flavor/manifest.rb', line 15 def required_fonts @required_fonts end |
#upstream ⇒ Object (readonly)
Returns the value of attribute upstream.
15 16 17 |
# File 'lib/arrolio/flavor/manifest.rb', line 15 def upstream @upstream end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
15 16 17 |
# File 'lib/arrolio/flavor/manifest.rb', line 15 def version @version end |
Class Method Details
.load(flavor_dir) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/arrolio/flavor/manifest.rb', line 19 def self.load(flavor_dir) manifest_path = File.join(flavor_dir, 'manifest.yml') unless File.exist?(manifest_path) raise ::Arrolio::FlavorError.new( "manifest.yml not found in #{flavor_dir}", flavor_dir: flavor_dir ) end data = YAML.safe_load_file(manifest_path, aliases: true) unless data.is_a?(Hash) raise ::Arrolio::FlavorError.new( "manifest.yml at #{manifest_path} is not a YAML mapping", flavor_dir: flavor_dir ) end validate_required_fields!(data, manifest_path) validate_config_files!(data, manifest_path, flavor_dir) new(manifest_path, data) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/arrolio/flavor/manifest.rb', line 63 def ==(other) other.is_a?(self.class) && path == other.path && name == other.name && version == other.version && description == other.description && doctypes == other.doctypes && required_fonts == other.required_fonts && optional_fonts == other.optional_fonts && config_files == other.config_files end |
#config_path_for(role, flavor_dir = File.dirname(@path)) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/arrolio/flavor/manifest.rb', line 56 def config_path_for(role, flavor_dir = File.dirname(@path)) file = config_files[role.to_s] || config_files[role.to_sym] return nil unless file File.join(flavor_dir, file) end |
#hash ⇒ Object
77 78 79 |
# File 'lib/arrolio/flavor/manifest.rb', line 77 def hash [self.class, path, name, version, config_files].hash end |