Class: Hiera::Config

### Home Classes Methods

### In Files

- lib/hiera/config.rb

### Parent

Object

### Methods

- ::[]
- ::include?
- ::load
- ::load_backends
- ::validate!

### 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::Config

### Public Class Methods

[](key) click to toggle source

    # File lib/hiera/config.rb, line 88
    def [](key)
      @config[key]
    end

include?(key) click to toggle source

    # File lib/hiera/config.rb, line 84
    def include?(key)
      @config.include?(key)
    end

load(source) click to toggle source

load takes a string or hash as input, strings are treated as filenames hashes are stored as data that would have been in the config file

Unless specified it will only use YAML as backend with a single 'common' hierarchy and console logger

@return [Hash] representing the configuration. e.g.

    {:backends => "yaml", :hierarchy => "common"}

    # File lib/hiera/config.rb, line 12
    def load(source)
      @config = {:backends => "yaml",
                 :hierarchy => "common",
                 :merge_behavior => :native }

      if source.is_a?(String)
        if File.exist?(source)
          config = begin
                     yaml_load_file(source)
                   rescue TypeError => detail
                     case detail.message
                     when /no implicit conversion from nil to integer/
                       false
                     else
                       raise detail
                     end
                   end
          @config.merge! config if config
        else
          raise "Config file #{source} not found"
        end
      elsif source.is_a?(Hash)
        @config.merge! source
      end

      @config[:backends] = [ @config[:backends] ].flatten

      if @config.include?(:logger)
        Hiera.logger = @config[:logger].to_s
      else
        @config[:logger] = "console"
        Hiera.logger = "console"
      end

      self.validate!

      @config
    end

load_backends() click to toggle source

    # File lib/hiera/config.rb, line 74
    def load_backends
      @config[:backends].each do |backend|
        begin
          require "hiera/backend/#{backend.downcase}_backend"
        rescue LoadError => e
          Hiera.warn "Cannot load backend #{backend}: #{e}"
        end
      end
    end

validate!() click to toggle source

    # File lib/hiera/config.rb, line 51
    def validate!
      case @config[:merge_behavior]
      when :deep,'deep',:deeper,'deeper'
        begin
          require "deep_merge"
        rescue LoadError
          Hiera.warn "Ignoring configured merge_behavior"
          Hiera.warn "Must have 'deep_merge' gem installed."
          @config[:merge_behavior] = :native
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.