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
Constant Summary collapse
- DEFAULT_PROFILE_NAME =
Any configuration set always contains ‘default` profile which is loaded when no profile requested.
'default'.freeze
- DEFAULT_CONFIGURATION =
Creates “empty” config
-> () { { DEFAULT_PROFILE_NAME => {} } }
Instance Attribute Summary collapse
-
#merger ⇒ Object
readonly
Creates configuration reader name for this stream.
Instance Method Summary collapse
-
#initialize(streams) ⇒ ConfigurationReader
constructor
A new instance of ConfigurationReader.
-
#read(*profile) ⇒ OpenStruct
Parses all streams and resolves requested profile merged.
Constructor Details
#initialize(streams) ⇒ ConfigurationReader
Returns a new instance of ConfigurationReader.
158 159 160 161 |
# File 'lib/jac/configuration.rb', line 158 def initialize(streams) @streams = streams @merger = Merger.new end |
Instance Attribute Details
#merger ⇒ Object (readonly)
Creates configuration reader name for this stream
157 158 159 |
# File 'lib/jac/configuration.rb', line 157 def merger @merger end |
Instance Method Details
#read(*profile) ⇒ OpenStruct
Parses all streams and resolves requested profile merged
167 168 169 170 171 172 |
# File 'lib/jac/configuration.rb', line 167 def read(*profile) result = @streams .flat_map { |stream, _name| read_stream(stream) } .inject(DEFAULT_CONFIGURATION.call) { |acc, elem| update(acc, elem) } OpenStruct.new(evaluate(resolve(profile, result)).merge('profile' => profile)) end |