Class: Hieracles::Hiera

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

Instance Method Summary collapse

Constructor Details

#initializeHiera

Returns a new instance of Hiera.

Raises:

  • (IOError)


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

def initialize
  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



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

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

#datapathObject

Raises:

  • (TypeError)


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

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



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

def hierarchy
  @loaded[:hierarchy]
end

#merge_behaviorObject



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

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

#paramsObject



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

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