Class: Konfig::Evaluator
- Inherits:
-
Object
- Object
- Konfig::Evaluator
- Defined in:
- lib/konfig/evaluator.rb
Overview
Used by Konfig::Store to evaluate inline code pulled from configuration files.
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
-
#initialize(data) ⇒ Evaluator
constructor
Set up the evaluator.
-
#names_by_value(a) ⇒ Hash
Converts an options-style nested array into a hash for easy name lookup.
-
#run(code) ⇒ Object
Runs a code fragment.
Constructor Details
#initialize(data) ⇒ Evaluator
Set up the evaluator
11 12 13 |
# File 'lib/konfig/evaluator.rb', line 11 def initialize(data) @data = data end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
7 8 9 |
# File 'lib/konfig/evaluator.rb', line 7 def data @data end |
Instance Method Details
#names_by_value(a) ⇒ Hash
Converts an options-style nested array into a hash for easy name lookup
26 27 28 29 |
# File 'lib/konfig/evaluator.rb', line 26 def names_by_value(a) a = @data[a] if a.is_a?(String) || a.is_a?(Symbol) Hash[ a.map { |i| i.reverse } ] end |
#run(code) ⇒ Object
Runs a code fragment
18 19 20 |
# File 'lib/konfig/evaluator.rb', line 18 def run(code) eval(code, binding) end |