Class: Hiera
- Inherits:
-
Object
- Object
- Hiera
- 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
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
- .debug(msg) ⇒ Object
-
.logger=(logger) ⇒ Object
Loggers are pluggable, just provide a class called Hiera::Foo_logger and respond to :warn and :debug.
- .version ⇒ Object
- .warn(msg) ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Hiera
constructor
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.
-
#lookup(key, default, scope, order_override = nil, resolution_type = :priority) ⇒ Object
Calls the backends to do the actual lookup.
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(={}) [:config] ||= "/etc/hiera.yaml" @config = Config.load([:config]) Config.load_backends end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
37 38 39 |
# File 'lib/hiera.rb', line 37 def config @config end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
37 38 39 |
# File 'lib/hiera.rb', line 37 def @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 |
.version ⇒ Object
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 |