class YleTf::Config

Configuration object to be used especially by the middleware stack

Constants

DEFAULT_NOT_FOUND_BLOCK
NotFoundError

Attributes

config[R]
module_dir[R]
tf_env[R]

Public Class Methods

load(tf_env) click to toggle source

Loads the configuration based on the environment

# File lib/yle_tf/config.rb, line 16
def self.load(tf_env)
  opts = {
    tf_env:     tf_env,
    module_dir: Pathname.pwd
  }

  config = Loader.new(opts).load
  new(config, **opts)
end
new(config, **opts) click to toggle source
# File lib/yle_tf/config.rb, line 28
def initialize(config, **opts)
  @config = config
  @tf_env = opts[:tf_env]
  @module_dir = opts[:module_dir]
end

Public Instance Methods

fetch(*keys, &block) click to toggle source

Returns a value from the configuration hierarchy specified by a list of keys. If the key is not specified, return result of a specied block, or raise `NotFoundError` if none specified.

# File lib/yle_tf/config.rb, line 41
def fetch(*keys, &block)
  block ||= DEFAULT_NOT_FOUND_BLOCK

  keys.inject(config) do |conf, key|
    next conf[key] if conf.is_a?(Hash) && conf.key?(key)

    if !conf.nil? && !conf.is_a?(Hash)
      Logger.warn(
        "Configuration [#{keys.join(' > ')}] includes non-hash element #{conf.inspect}"
      )
    end

    break block.call(keys)
  end
end
to_s() click to toggle source
# File lib/yle_tf/config.rb, line 34
def to_s
  YAML.dump(config)
end