Sha256: 982f40e2c5a850656a445827526547275478d3a5d443562eba78023ca83ef163

Contents?: true

Size: 1018 Bytes

Versions: 3

Compression:

Stored size: 1018 Bytes

Contents

require 'hiera'
require 'active_support'
require 'active_support/core_ext/hash/keys'

module Confidante
  class Configuration
    def initialize(opts = {})
      options = {
          overrides: {},
          scope: {},
      }.merge(opts.to_options)

      unless options[:hiera]
        options[:hiera] = Hiera.new(config: 'config/hiera.yaml')
      end

      @overrides = options[:overrides]
      @scope = options[:scope]
      @hiera = options[:hiera]
    end

    def for_overrides(overrides)
      Configuration.new(
          overrides: overrides,
          scope: @scope,
          hiera: @hiera)
    end

    def for_scope(scope)
      Configuration.new(
          overrides: @overrides,
          scope: scope,
          hiera: @hiera)
    end

    def method_missing(method, *args, &block)
      @hiera.lookup(
          method.to_s,
          nil,
          {'cwd' => Dir.pwd}
              .merge(@scope.stringify_keys)
              .merge({'overrides' => @overrides.stringify_keys}))
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
confidante-0.5.0 lib/confidante/configuration.rb
confidante-0.4.0 lib/confidante/configuration.rb
confidante-0.3.0 lib/confidante/configuration.rb