Module: Antlers::Variables

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

Instance Method Summary collapse

Methods included from Queries

user_defined_string?, wrapped_in?

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


12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/modules/variables.rb', line 12

def evaluate(name:, current_binding:)
  return name.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

  nil
rescue StandardError
  nil
end

#fallback(value) ⇒ Object



26
27
28
29
30
# File 'lib/modules/variables.rb', line 26

def fallback(value)
  return value[1..-2] if Queries.user_defined_string?(value)

  value
end