Class: Jac::Configuration::ConfigurationReader
- Inherits:
-
Object
- Object
- Jac::Configuration::ConfigurationReader
- Defined in:
- lib/jac/configuration.rb
Overview
Reads and evaluates configuration for given set of streams and profile
Instance Attribute Summary collapse
-
#merger ⇒ Object
readonly
Returns the value of attribute merger.
Instance Method Summary collapse
-
#initialize(streams) ⇒ ConfigurationReader
constructor
Creates configuration reader.
-
#read(*profile) ⇒ OpenStruct
Parses all streams and resolves requested profile.
Constructor Details
#initialize(streams) ⇒ ConfigurationReader
Creates configuration reader
206 207 208 209 |
# File 'lib/jac/configuration.rb', line 206 def initialize(streams) @streams = streams @merger = Merger.new end |
Instance Attribute Details
#merger ⇒ Object (readonly)
Returns the value of attribute merger.
202 203 204 |
# File 'lib/jac/configuration.rb', line 202 def merger @merger end |
Instance Method Details
#read(*profile) ⇒ OpenStruct
Parses all streams and resolves requested profile
214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/jac/configuration.rb', line 214 def read(*profile) result = @streams .flat_map { |stream, _name| read_stream(stream) } .inject(default_configuration) { |acc, elem| update(acc, elem) } # Keep original profile name original_profile = profile # Add implicit profiles profile = [Configuration::BASE_PROFILE_NAME, profile, Configuration::TOP_PROFILE_NAME].flatten OpenStruct.new(evaluate(resolve(profile, result).merge('profile' => original_profile))) end |