Class: Hiera::Backend::Yaml_backend

### Home Classes Methods

### In Files

- lib/hiera/backend/yaml_backend.rb

### Parent

Object

### Methods

- ::new
- #lookup

### Class/Module Index

Quicksearch

- Hiera
- Hiera::Backend
- Hiera::Backend::Json_backend
- Hiera::Backend::Yaml_backend
- Hiera::Config
- Hiera::Console_logger
- Hiera::Error
- Hiera::FallbackLogger
- Hiera::Filecache
- Hiera::Interpolate
- Hiera::InterpolationLoop
- Hiera::InvalidConfigurationError
- Hiera::Noop_logger
- Hiera::Puppet_logger
- Hiera::RecursiveGuard
- Hiera::Util

No matching classes.

# Hiera::Backend::Yaml_backend

### Public Class Methods

new(cache=nil) click to toggle source

    # File lib/hiera/backend/yaml_backend.rb, line 4
    def initialize(cache=nil)
      require 'yaml'
      Hiera.debug("Hiera YAML backend starting")

      @cache = cache || Filecache.new
    end

### Public Instance Methods

lookup(key, scope, order_override, resolution_type) click to toggle source

    # File lib/hiera/backend/yaml_backend.rb, line 11
    def lookup(key, scope, order_override, resolution_type)
      answer = nil

      Hiera.debug("Looking up #{key} in YAML backend")

      Backend.datasourcefiles(:yaml, scope, "yaml", order_override) do |source, yamlfile|
        data = @cache.read_file(yamlfile, Hash) do |data|
          YAML.load(data) || {}
        end

        next if data.empty?
        next unless data.include?(key)

        # Extra logging that we found the key. This can be outputted
        # multiple times if the resolution type is array or hash but that
        # should be expected as the logging will then tell the user ALL the
        # places where the key is found.
        Hiera.debug("Found #{key} in #{source}")

        # for array resolution we just append to the array whatever
        # we find, we then goes onto the next file and keep adding to
        # the array
        #
        # for priority searches we break after the first found data item
        new_answer = Backend.parse_answer(data[key], scope)
        case resolution_type
        when :array
          raise Exception, "Hiera type mismatch: expected Array and got #{new_answer.class}" unless new_answer.kind_of? Array or new_answer.kind_of? String
          answer ||= []
          answer << new_answer
        when :hash
          raise Exception, "Hiera type mismatch: expected Hash and got #{new_answer.class}" unless new_answer.kind_of? Hash
          answer ||= {}
          answer = Backend.merge_answer(new_answer,answer)
        else
          answer = new_answer
          break
        end
      end

      return answer
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.