Module Hiera::Backend
In: lib/hiera/backend.rb
lib/hiera/backend/json_backend.rb
lib/hiera/backend/yaml_backend.rb

Methods

Classes and Modules

Class Hiera::Backend::Json_backend
Class Hiera::Backend::Yaml_backend

Public Class methods

Data lives in /var/lib/hiera by default. If a backend supplies a datadir in the config it will be used and subject to variable expansion based on scope

Finds the path to a datafile based on the Backend#datadir and extension

If the file is not found nil is returned

Constructs a list of data files to search

If you give it a specific hierarchy it will just use that else it will use the global configured one, failing that it will just look in the ‘common’ data source.

An override can be supplied that will be pre-pended to the hierarchy.

The source names will be subject to variable expansion based on scope

Only files that exist will be returned. If the file is missing, then the block will not receive the file.

@yield [String, String] the source string and the name of the resulting file @api public

Constructs a list of data sources to search

If you give it a specific hierarchy it will just use that else it will use the global configured one, failing that it will just look in the ‘common’ data source.

An override can be supplied that will be pre-pended to the hierarchy.

The source names will be subject to variable expansion based on scope

Calls out to all configured backends in the order they were specified. The first one to answer will win.

This lets you declare multiple backends, a possible use case might be in Puppet where a Puppet module declares default data using in-module data while users can override using JSON/YAML etc. By layering the backends and putting the Puppet one last you can override module author data easily.

Backend instances are cached so if you need to connect to any databases then do so in your constructor, future calls to your backend will not create new instances

Merges two hashes answers with the configured merge behavior.

        :merge_behavior: {:native|:deep|:deeper}

Deep merge options use the Hash utility function provided by [deep_merge](github.com/peritor/deep_merge)

 :native => Native Hash.merge
 :deep   => Use Hash.deep_merge
 :deeper => Use Hash.deep_merge!

Parses a answer received from data files

Ultimately it just pass the data through parse_string but it makes some effort to handle arrays of strings as well

Parse a string like ’%{foo}’ against a supplied scope and additional scope. If either scope or extra_scope includes the variable ‘foo’, then it will be replaced else an empty string will be placed.

If both scope and extra_data has "foo", then the value in scope will be used.

@param data [String] The string to perform substitutions on.

  This will not be modified, instead a new string will be returned.

@param scope [#[]] The primary source of data for substitutions. @param extra_data [#[]] The secondary source of data for substitutions. @return [String] A copy of the data with all instances of %{…} replaced.

@api public

[Validate]