Class: Hiera

Inherits:
Object
  • Object
show all
Defined in:
lib/hiera.rb,
lib/hiera/backend.rb,
lib/hiera/puppet_logger.rb,
lib/hiera/console_logger.rb,
lib/hiera/backend/yaml_backend.rb

Defined Under Namespace

Modules: Backend, Console_logger, Puppet_logger Classes: Config

Constant Summary collapse

VERSION =
"0.3.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Hiera

If the config option is a string its assumed to be a filename, else a hash of what would have been in the YAML config file



41
42
43
44
45
46
47
# File 'lib/hiera.rb', line 41

def initialize(options={})
    options[:config] ||= "/etc/hiera.yaml"

    @config = Config.load(options[:config])

    Config.load_backends
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



37
38
39
# File 'lib/hiera.rb', line 37

def config
  @config
end

#optionsObject (readonly)

Returns the value of attribute options.



37
38
39
# File 'lib/hiera.rb', line 37

def options
  @options
end

Class Method Details

.debug(msg) ⇒ Object



34
# File 'lib/hiera.rb', line 34

def debug(msg); @logger.debug(msg); end

.logger=(logger) ⇒ Object

Loggers are pluggable, just provide a class called Hiera::Foo_logger and respond to :warn and :debug

See hiera-puppet for an example that uses the Puppet loging system instead of our own



22
23
24
25
26
27
28
29
30
31
# File 'lib/hiera.rb', line 22

def logger=(logger)
    loggerclass = "#{logger.capitalize}_logger"

    require "hiera/#{logger}_logger" unless constants.include?(loggerclass)

    @logger = const_get(loggerclass)
rescue Exception => e
    @logger = Console_logger
    warn("Failed to load #{logger} logger: #{e.class}: #{e}")
end

.versionObject



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

def version
    VERSION
end

.warn(msg) ⇒ Object



33
# File 'lib/hiera.rb', line 33

def warn(msg); @logger.warn(msg); end

Instance Method Details

#lookup(key, default, scope, order_override = nil, resolution_type = :priority) ⇒ Object

Calls the backends to do the actual lookup.

The scope can be anything that responds to [], if you have input data like a Puppet Scope that does not you can wrap that data in a class that has a [] method that fetches the data from your source. See hiera-puppet for an example of this.

The order-override will insert as first in the hierarchy a data source of your choice.



58
59
60
# File 'lib/hiera.rb', line 58

def lookup(key, default, scope, order_override=nil, resolution_type=:priority)
    Backend.lookup(key, default, scope, order_override, resolution_type)
end