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

Creates configuration reader

Parameters:

  • streams (Array)

    of pairs containing YAML document and provided name for this stream


192
193
194
195
# File 'lib/jac/configuration.rb', line 192

def initialize(streams)
  @streams = streams
  @merger = Merger.new
end

Instance Attribute Details

#mergerObject (readonly)

Returns the value of attribute merger


188
189
190
# File 'lib/jac/configuration.rb', line 188

def merger
  @merger
end

Instance Method Details

#read(*profile) ⇒ OpenStruct

Parses all streams and resolves requested profile

Parameters:

  • profile (Array)

    list of profile names to be merged

Returns:

  • (OpenStruct)

    instance which contains all resolved profile fields


200
201
202
203
204
205
# File 'lib/jac/configuration.rb', line 200

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