Class: ExceptionResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/block_repeater/exception_response.rb

Overview

Store an execute behaviour in response to an exception being raised

Constant Summary collapse

BEHAVIOURS =
%i[continue stop defer].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(types: [], behaviour: :defer, &block) ⇒ ExceptionResponse

Returns a new instance of ExceptionResponse.



10
11
12
13
14
15
16
17
# File 'lib/block_repeater/exception_response.rb', line 10

def initialize(types: [], behaviour: :defer, &block)
  raise "Exception handling behaviour '#{behaviour}' not recognised" unless BEHAVIOURS.include? behaviour
  raise 'No exception types provided' if [*types].count.zero?

  @types = [*types]
  @behaviour = behaviour
  @response = block || default_proc
end

Instance Attribute Details

#actualObject

Returns the value of attribute actual.



6
7
8
# File 'lib/block_repeater/exception_response.rb', line 6

def actual
  @actual
end

#behaviourObject

Returns the value of attribute behaviour.



6
7
8
# File 'lib/block_repeater/exception_response.rb', line 6

def behaviour
  @behaviour
end

#responseObject

Returns the value of attribute response.



6
7
8
# File 'lib/block_repeater/exception_response.rb', line 6

def response
  @response
end

#typesObject

Returns the value of attribute types.



6
7
8
# File 'lib/block_repeater/exception_response.rb', line 6

def types
  @types
end

Instance Method Details

#execute(exception = nil) ⇒ Object



19
20
21
# File 'lib/block_repeater/exception_response.rb', line 19

def execute(exception = nil)
  @response.call(exception || @actual)
end