Class: FEEL::QualifiedName
- Defined in:
- lib/feel/nodes.rb
Overview
-
qualified name = name , { “.” , name } ;
Instance Method Summary collapse
-
#context_get(context, key, root: :nil) ⇒ Object
Get a key from the context, using symbol/string lookup, with errors if need be, and optionally overriding the root object for full path during errors.
- #eval(context = {}) ⇒ Object
Methods inherited from Node
#qualified_names_in_context, #raise_evaluation_error
Instance Method Details
#context_get(context, key, root: :nil) ⇒ Object
Get a key from the context, using symbol/string lookup, with errors if need be, and optionally overriding the root object for full path during errors.
247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/feel/nodes.rb', line 247 def context_get(context, key, root: :nil) root = context if root == :nil if context.key?(key.to_sym) context[key.to_sym] elsif context.key?(key) context[key] else raise_evaluation_error(head.text_value + tail.text_value, root) if FEEL.config.strict nil end end |
#eval(context = {}) ⇒ Object
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/feel/nodes.rb', line 226 def eval(context = {}) head_name = head.eval(context) if tail.empty? context_get(context, head_name) else initial_value = context_get(context, head_name) # Process each segment in the tail, evaluating names to handle backticks tail.elements.inject(initial_value) do |hash, element| return nil unless hash key = element.name.eval(context) context_get(hash, key, root: context) end end end |