Class: MiniHiera
- Inherits:
-
Object
- Object
- MiniHiera
- Defined in:
- lib/mini_hiera.rb,
lib/mini_hiera/version.rb
Defined Under Namespace
Classes: Context
Constant Summary collapse
- CircularReferenceError =
Class.new(RuntimeError)
- KeyNotFoundError =
Class.new(RuntimeError)
- CACHE =
{}
- TYPES =
{ "yaml" => Proc.new { |filename| cache(filename) { YAML.load(File.read(filename), filename) } }, "json" => Proc.new { |filename| cache(filename) { JSON.load(File.read(filename), filename) } } }
- VERSION =
"0.1.2"
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
Instance Method Summary collapse
- #context(data = {}, options = {}) ⇒ Object
-
#initialize(config, options = {}) ⇒ MiniHiera
constructor
A new instance of MiniHiera.
- #load_path(path) ⇒ Object
- #replace(string, dictionary) ⇒ Object
- #resolve(data) ⇒ Object
Constructor Details
#initialize(config, options = {}) ⇒ MiniHiera
Returns a new instance of MiniHiera.
16 17 18 19 |
# File 'lib/mini_hiera.rb', line 16 def initialize(config, ={}) @config = config @options = end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
15 16 17 |
# File 'lib/mini_hiera.rb', line 15 def config @config end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/mini_hiera.rb', line 15 def @options end |
Class Method Details
Instance Method Details
#context(data = {}, options = {}) ⇒ Object
129 130 131 |
# File 'lib/mini_hiera.rb', line 129 def context(data={}, ={}) Context.new(self, data, @options.deep_merge()) end |
#load_path(path) ⇒ Object
121 122 123 |
# 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) ⇒ Object
100 101 102 103 104 |
# File 'lib/mini_hiera.rb', line 100 def replace(string, dictionary) string.gsub(/\%\{([^}]+)\}/) do |match| dictionary.fetch($1, match) end end |
#resolve(data) ⇒ Object
125 126 127 |
# 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 |