Class: Hieracles::Hiera

Inherits:
Object
  • Object
show all
Defined in:
lib/hieracles/hiera.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Hiera

Returns a new instance of Hiera.

Raises:

  • (IOError)


4
5
6
7
8
9
# File 'lib/hieracles/hiera.rb', line 4

def initialize(config)
  @config = config
  raise IOError, "Hierafile #{@config.hierafile} not found." unless File.exist? @config.hierafile
  @hierafile = @config.hierafile
  @loaded = YAML.load_file(@hierafile)
end

Instance Method Details

#datadirObject



22
23
24
# File 'lib/hieracles/hiera.rb', line 22

def datadir
  @loaded[:yaml][:datadir]
end

#datapathObject

Raises:

  • (TypeError)


11
12
13
14
15
16
# File 'lib/hieracles/hiera.rb', line 11

def datapath
  raise TypeError, "Sorry hieracles only knows yaml backend for now." unless @loaded[:yaml]
  parampath = File.expand_path(File.join(@config.basepath, datadir))
  raise IOError, "Params dir #{parampath} not found." unless Dir.exist? parampath
  parampath
end

#hierarchyObject



18
19
20
# File 'lib/hieracles/hiera.rb', line 18

def hierarchy
  @loaded[:hierarchy]
end

#merge_behaviorObject



30
31
32
33
34
35
36
37
# File 'lib/hieracles/hiera.rb', line 30

def merge_behavior
  case @loaded[:merge_behavior]
  when :deep,'deep',:deeper,'deeper'
    @loaded[:merge_behavior].to_sym
  else
    :native
  end
end

#paramsObject



26
27
28
# File 'lib/hieracles/hiera.rb', line 26

def params
  hierarchy.join(',').scan(/%\{(?:::)?([^\}]*)\}/).flatten.uniq
end