Class: Confidante::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/confidante/configuration.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Configuration

Returns a new instance of Configuration.



11
12
13
14
15
16
17
18
# File 'lib/confidante/configuration.rb', line 11

def initialize(opts = {})
  options = opts.to_options

  @overrides = default_overrides(options[:overrides])
  @scope = default_scope(options[:scope])
  @hiera = default_hiera(options[:hiera])
  @converters = default_converters(options[:converters])
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *_args) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/confidante/configuration.rb', line 38

def method_missing(method, *_args)
  scope =
    { 'cwd' => Dir.pwd }
    .merge(@scope.stringify_keys)
    .merge({ 'overrides' => @overrides.to_h.stringify_keys })
  @converters.inject(@hiera.lookup(method.to_s, nil, scope)) do |v, c|
    c.convert(v)
  end
end

Instance Method Details

#for_overrides(overrides) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/confidante/configuration.rb', line 20

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

#for_scope(scope) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/confidante/configuration.rb', line 29

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

#respond_to_missing?(_method_name, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/confidante/configuration.rb', line 48

def respond_to_missing?(_method_name, _include_private = false)
  true
end