Module: Yutani::Hiera

Included in:
Data, Provider, RemoteConfig, Resource, Stack, Template
Defined in:
lib/yutani/hiera.rb

Defined Under Namespace

Classes: NonExistentKeyException

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.hiera(config_override = {}) ⇒ Object

Returns the value of attribute hiera.



17
18
19
# File 'lib/yutani/hiera.rb', line 17

def hiera
  @hiera
end

.scopesObject

Returns the value of attribute scopes.



17
18
19
# File 'lib/yutani/hiera.rb', line 17

def scopes
  @scopes
end

Class Method Details

.init_hiera(override = {}) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/yutani/hiera.rb', line 38

def init_hiera(override={})
  conf = Yutani.config(override)

  # hiera_config_file trumps hiera_config
  ::Hiera.new(config:
    conf.fetch('hiera_config_file', conf['hiera_config'])
  )
end

.lookup(k) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/yutani/hiera.rb', line 47

def lookup(k)

  # hiera expects key to be a string
  v = hiera.lookup(k.to_s, nil, scope)

  raise NonExistentKeyException.new(v) if v.nil?

  # if nested hash, let user lookup nested keys with strings or symbols
  Yutani::Utils.convert_nested_hash_to_indifferent_access(v)
end

.popObject



30
31
32
# File 'lib/yutani/hiera.rb', line 30

def pop
  @scopes.pop
end

.push(kv) ⇒ Object



23
24
25
26
27
28
# File 'lib/yutani/hiera.rb', line 23

def push(kv)
  # hiera doesn't accept symbols for scope keys or values
  @scopes.push Yutani::Utils.convert_symbols_to_strings_in_flat_hash(kv)

  Yutani.logger.debug "hiera scope: %s" % scope
end

.scopeObject



19
20
21
# File 'lib/yutani/hiera.rb', line 19

def scope
  @scopes.inject({}){|h,scope| h.merge(scope) }
end

Instance Method Details

#hiera(k) ⇒ Object



12
13
14
# File 'lib/yutani/hiera.rb', line 12

def hiera(k)
  Hiera.lookup(k)
end