Class: Jac::Configuration::ConfigurationReader

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#mergerObject (readonly)

Creates configuration reader name for this stream

Parameters:

  • streams (Array)

    of pairs containing YAML document and provided



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

Parameters:

  • profile (Array)

    list of profile names to be

Returns:

  • (OpenStruct)

    instance which contains all resolved profile fields



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