Class: Sablon::Statement::Loop
- Inherits:
-
Struct
- Object
- Struct
- Sablon::Statement::Loop
- Defined in:
- lib/sablon/operations.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#iterator_name ⇒ Object
Returns the value of attribute iterator_name.
-
#list_expr ⇒ Object
Returns the value of attribute list_expr.
Instance Method Summary collapse
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block
14 15 16 |
# File 'lib/sablon/operations.rb', line 14 def block @block end |
#iterator_name ⇒ Object
Returns the value of attribute iterator_name
14 15 16 |
# File 'lib/sablon/operations.rb', line 14 def iterator_name @iterator_name end |
#list_expr ⇒ Object
Returns the value of attribute list_expr
14 15 16 |
# File 'lib/sablon/operations.rb', line 14 def list_expr @list_expr end |
Instance Method Details
#evaluate(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/sablon/operations.rb', line 15 def evaluate(env) value = list_expr.evaluate(env.context) value = value.to_ary if value.respond_to?(:to_ary) raise ContextError, "The expression #{list_expr.inspect} should evaluate to an enumerable but was: #{value.inspect}" unless value.is_a?(Enumerable) content = value.flat_map do |item| iter_env = env.alter_context(iterator_name => item) block.process(iter_env) end update_unique_ids(env, content) block.replace(content.reverse) end |