class MiniHiera

Constants

CACHE
CircularReferenceError
KeyNotFoundError
TYPES
VERSION

Attributes

config[R]
options[R]

Public Class Methods

cache(filename) click to toggle source
# File lib/mini_hiera.rb, line 108
def self.cache(filename)
  if CACHE.keys.include?(filename)
    CACHE[filename]
  else
    CACHE[filename] = yield
  end
end
new(config, options={}) click to toggle source
# File lib/mini_hiera.rb, line 16
def initialize(config, options={})
  @config = config
  @options = options
end

Public Instance Methods

context(data={}, options={}) click to toggle source
# File lib/mini_hiera.rb, line 129
def context(data={}, options={})
  Context.new(self, data, @options.deep_merge(options))
end
load_path(path) click to toggle source
# File lib/mini_hiera.rb, line 121
def load_path(path)
  TYPES.map { |s,proc| ["#{path}.#{s}", proc] }.find_value { |filename,proc| proc.call(filename, binding) if File.exist?(filename) }
end
replace(string, dictionary) click to toggle source
# File lib/mini_hiera.rb, line 100
def replace(string, dictionary)
  string.gsub(/\%\{([^}]+)\}/) do |match|
    dictionary.fetch($1, match)
  end
end
resolve(data) click to toggle source
# File lib/mini_hiera.rb, line 125
def resolve(data)
  [data] + @options[:hierarchy].map { |path| load_path(File.join(@config, replace(path, data))) }.compact
end