Class: Mortar::Config
- Inherits:
-
Object
- Object
- Mortar::Config
- Defined in:
- lib/mortar/config.rb
Defined Under Namespace
Classes: ConfigError
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(variables: {}, overlays: []) ⇒ Config
constructor
A new instance of Config.
- #overlays(other = []) ⇒ Object
- #variables(other = {}) ⇒ RecursiveOpenStruct
Constructor Details
#initialize(variables: {}, overlays: []) ⇒ Config
Returns a new instance of Config.
16 17 18 19 |
# File 'lib/mortar/config.rb', line 16 def initialize(variables: {}, overlays: []) @variables = variables @overlays = end |
Class Method Details
.load(path) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/mortar/config.rb', line 7 def self.load(path) cfg = YAML.safe_load(File.read(path)) raise ConfigError, "Failed to load config, check config file syntax" unless cfg.is_a? Hash raise ConfigError, "Failed to load config, overlays needs to be an array" if cfg.key?('overlays') && !cfg['overlays'].is_a?(Array) new(variables: cfg['variables'] || {}, overlays: cfg['overlays'] || []) end |
Instance Method Details
#overlays(other = []) ⇒ Object
28 29 30 31 32 |
# File 'lib/mortar/config.rb', line 28 def (other = []) return @overlays unless other (@overlays + other).uniq.compact end |
#variables(other = {}) ⇒ RecursiveOpenStruct
22 23 24 25 26 |
# File 'lib/mortar/config.rb', line 22 def variables(other = {}) hash = @variables.dup hash.deep_merge!(other) RecursiveOpenStruct.new(hash, recurse_over_arrays: true) end |