Class: Rjq::AST::Try

Inherits:
Node
  • Object
show all
Defined in:
lib/rjq/ast.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#source_span

Instance Method Summary collapse

Methods inherited from Node

#assign_value, #invalid_path_message, #paths, #take, #with_source_span

Constructor Details

#initialize(body, handler = nil) ⇒ Try

Returns a new instance of Try.



690
691
692
693
# File 'lib/rjq/ast.rb', line 690

def initialize(body, handler = nil)
  @body = body
  @handler = handler
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



688
689
690
# File 'lib/rjq/ast.rb', line 688

def body
  @body
end

#handlerObject (readonly)

Returns the value of attribute handler.



688
689
690
# File 'lib/rjq/ast.rb', line 688

def handler
  @handler
end

Instance Method Details

#eval(input, context) ⇒ Object



695
696
697
698
699
700
701
# File 'lib/rjq/ast.rb', line 695

def eval(input, context)
  @body.eval(input, context)
rescue Rjq::ErrorValue => e
  (e.outputs || []) + (@handler ? @handler.eval(e.value, context) : [])
rescue Rjq::RuntimeError => e
  @handler ? @handler.eval(e.message, context) : []
end