Class: Cadenza::InjectNode
- Inherits:
-
Object
- Object
- Cadenza::InjectNode
- Defined in:
- lib/cadenza/nodes/inject_node.rb
Overview
The InjectNode is intended to write the given variable into the rendered output by evaluating it in the given Context and passing it through an optional series of FilterNodes.
Instance Attribute Summary collapse
-
#filters ⇒ Array
A list of FilterNode to evaluate the value with, once the value has itself been evaluated.
-
#parameters ⇒ Array
A list of Node objects passed to the #value for use in a functional variable.
-
#value ⇒ VariableNode|OperationNode|BooleanInverseNode|ConstantNode
The value being evaluated.
Instance Method Summary collapse
-
#==(rhs) ⇒ Boolean
True if the given InjectNode is equivalent by value to this node.
-
#evaluate(context) ⇒ String
Returns the evaluated #value of this node in the given Context with any applicable #parameters after passed through the given #filters.
-
#implied_globals ⇒ Array
A list of variable names implied to be global by this node.
-
#initialize(value, filters = [], parameters = []) ⇒ InjectNode
constructor
creates a new InjectNode with the given value, filters and parameters.
Constructor Details
#initialize(value, filters = [], parameters = []) ⇒ InjectNode
creates a new Cadenza::InjectNode with the given value, filters and parameters
21 22 23 24 25 |
# File 'lib/cadenza/nodes/inject_node.rb', line 21 def initialize(value, filters=[], parameters=[]) @value = value @filters = filters @parameters = parameters end |
Instance Attribute Details
#filters ⇒ Array
Returns a list of FilterNode to evaluate the value with, once the value has itself been evaluated.
11 12 13 |
# File 'lib/cadenza/nodes/inject_node.rb', line 11 def filters @filters end |
#parameters ⇒ Array
Returns a list of Node objects passed to the #value for use in a functional variable. See Context#define_functional_variable.
15 16 17 |
# File 'lib/cadenza/nodes/inject_node.rb', line 15 def parameters @parameters end |
#value ⇒ VariableNode|OperationNode|BooleanInverseNode|ConstantNode
Returns the value being evaluated.
7 8 9 |
# File 'lib/cadenza/nodes/inject_node.rb', line 7 def value @value end |
Instance Method Details
#==(rhs) ⇒ Boolean
Returns true if the given InjectNode is equivalent by value to this node.
29 30 31 32 33 |
# File 'lib/cadenza/nodes/inject_node.rb', line 29 def ==(rhs) self.value == rhs.value and self.filters == rhs.filters and self.parameters == rhs.parameters end |
#evaluate(context) ⇒ String
Returns the evaluated #value of this node in the given Context with any applicable #parameters after passed through the given #filters.
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/cadenza/nodes/inject_node.rb', line 44 def evaluate(context) value = @value.eval(context) if value.is_a? Proc args = parameters.map {|p| p.eval(context) } value = value.call(context, *args) end @filters.each {|filter| value = filter.evaluate(context, value) } value end |
#implied_globals ⇒ Array
Returns a list of variable names implied to be global by this node.
36 37 38 |
# File 'lib/cadenza/nodes/inject_node.rb', line 36 def implied_globals (@value.implied_globals + @filters.map(&:implied_globals).flatten).uniq end |