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

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



206
207
208
209
# File 'lib/jac/configuration.rb', line 206

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

Instance Attribute Details

#mergerObject (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

Parameters:

  • profile (Array)

    list of profile names to be merged

Returns:

  • (OpenStruct)

    instance which contains all resolved profile fields



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