Module: Antlers::Variables

Included in:
ForNode, Props, VarNode
Defined in:
lib/modules/variables.rb

Instance Method Summary collapse

Instance Method Details

#evaluate(name:, current_binding:) ⇒ Object

Evaluation limited to the following for security and to prevent a templating language becoming a programming language.

1. An instance variable
2. A method call/local variable
3. A method chain
4. A static string


8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/modules/variables.rb', line 8

def evaluate(name:, current_binding:)
  return @value.to_s unless current_binding

  name, *chain = name.split('.')

  result = method_var(name:, current_binding:)
  return method_chain(result:, chain:, current_binding:) if chain.count > 0
  return result if result

  @value.to_s
rescue NameError
  @value.to_s
end