Class: NxtPipeline::ErrorCallback

Inherits:
Object
  • Object
show all
Defined in:
lib/nxt_pipeline/error_callback.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(errors, halt_on_error, &callback) ⇒ ErrorCallback

Returns a new instance of ErrorCallback.



3
4
5
6
7
# File 'lib/nxt_pipeline/error_callback.rb', line 3

def initialize(errors, halt_on_error, &callback)
  @errors = errors.any? ? errors : [StandardError]
  @halt_on_error = halt_on_error
  @callback = callback
end

Instance Attribute Details

#callbackObject

Returns the value of attribute callback.



9
10
11
# File 'lib/nxt_pipeline/error_callback.rb', line 9

def callback
  @callback
end

#errorsObject

Returns the value of attribute errors.



9
10
11
# File 'lib/nxt_pipeline/error_callback.rb', line 9

def errors
  @errors
end

Instance Method Details

#applies_to_error?(error) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/nxt_pipeline/error_callback.rb', line 19

def applies_to_error?(error)
  (error.class.ancestors & errors).any?
end

#call(error, acc, step) ⇒ Object



23
24
25
26
27
28
# File 'lib/nxt_pipeline/error_callback.rb', line 23

def call(error, acc, step)
  args = [error, acc, step]
  args = args.take(callback.arity) unless callback.arity.negative?

  callback.call(*args)
end

#continue_after_error?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/nxt_pipeline/error_callback.rb', line 15

def continue_after_error?
  !halt_on_error?
end

#halt_on_error?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/nxt_pipeline/error_callback.rb', line 11

def halt_on_error?
  @halt_on_error
end