Class: Rjq::AST::Field
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from Node
Instance Method Summary collapse
- #eval(input, context) ⇒ Object
-
#initialize(base, name, optional: false) ⇒ Field
constructor
A new instance of Field.
- #invalid_path_message(result, _input, _context) ⇒ Object
- #paths(input, context) ⇒ Object
Methods inherited from Node
#assign_value, #take, #with_source_span
Constructor Details
#initialize(base, name, optional: false) ⇒ Field
Returns a new instance of Field.
395 396 397 398 399 |
# File 'lib/rjq/ast.rb', line 395 def initialize(base, name, optional: false) @base = base @name = name @optional = optional end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
393 394 395 |
# File 'lib/rjq/ast.rb', line 393 def base @base end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
393 394 395 |
# File 'lib/rjq/ast.rb', line 393 def name @name end |
Instance Method Details
#eval(input, context) ⇒ Object
401 402 403 404 405 406 407 |
# File 'lib/rjq/ast.rb', line 401 def eval(input, context) @base.eval(input, context).flat_map do |value| [read(value)] rescue Rjq::RuntimeError @optional ? [] : raise end end |
#invalid_path_message(result, _input, _context) ⇒ Object
413 414 415 416 |
# File 'lib/rjq/ast.rb', line 413 def (result, _input, _context) "Invalid path expression near attempt to access element #{@name.inspect} of #{JSON::Dumper.dump(result, indent: nil)}" end |
#paths(input, context) ⇒ Object
409 410 411 |
# File 'lib/rjq/ast.rb', line 409 def paths(input, context) @base.paths(input, context).map { |path| path + [@name] } end |