Class: Nocode::Util::ObjectTemplate
- Inherits:
-
Object
- Object
- Nocode::Util::ObjectTemplate
- Defined in:
- lib/nocode/util/object_template.rb
Overview
Built on top of StringTemplate but instead of only working for a string, this will recursively evaluate all strings within an object. Heuristics:
- Strings evaluate using StringTemplate
- Hashes will have their keys and values traversed
- Arrays will have their entries traversed
- All other types will simply return themselves
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
- #evaluate(values = {}) ⇒ Object
-
#initialize(object) ⇒ ObjectTemplate
constructor
A new instance of ObjectTemplate.
Constructor Details
#initialize(object) ⇒ ObjectTemplate
Returns a new instance of ObjectTemplate.
16 17 18 19 20 |
# File 'lib/nocode/util/object_template.rb', line 16 def initialize(object) @object = object freeze end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
14 15 16 |
# File 'lib/nocode/util/object_template.rb', line 14 def object @object end |
Instance Method Details
#evaluate(values = {}) ⇒ Object
22 23 24 |
# File 'lib/nocode/util/object_template.rb', line 22 def evaluate(values = {}) recursive_evaluate(object, values) end |