Class: Gitlab::TemplateParser::AST::Each

Inherits:
Struct
  • Object
show all
Defined in:
lib/gitlab/template_parser/ast.rb

Overview

An `each` expression.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body


111
112
113
# File 'lib/gitlab/template_parser/ast.rb', line 111

def body
  @body
end

#collectionObject

Returns the value of attribute collection

Returns:

  • (Object)

    the current value of collection


111
112
113
# File 'lib/gitlab/template_parser/ast.rb', line 111

def collection
  @collection
end

Instance Method Details

#evaluate(state, data) ⇒ Object


112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/gitlab/template_parser/ast.rb', line 112

def evaluate(state, data)
  values = collection.evaluate(state, data)

  return '' unless values.respond_to?(:each)

  # While unlikely to happen, it's possible users attempt to nest many
  # loops in order to negatively impact the GitLab instance. To make
  # this more difficult, we limit the number of nested loops a user can
  # create.
  state.enter_loop do
    values.map { |value| body.evaluate(state, value) }.join('')
  end
end