Class: ExceptionResponse
- Inherits:
-
Object
- Object
- ExceptionResponse
- 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
-
#actual ⇒ Object
Returns the value of attribute actual.
-
#behaviour ⇒ Object
Returns the value of attribute behaviour.
-
#response ⇒ Object
Returns the value of attribute response.
-
#types ⇒ Object
Returns the value of attribute types.
Instance Method Summary collapse
- #execute(exception = nil) ⇒ Object
-
#initialize(types: [], behaviour: :defer, &block) ⇒ ExceptionResponse
constructor
A new instance of ExceptionResponse.
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
#actual ⇒ Object
Returns the value of attribute actual.
6 7 8 |
# File 'lib/block_repeater/exception_response.rb', line 6 def actual @actual end |
#behaviour ⇒ Object
Returns the value of attribute behaviour.
6 7 8 |
# File 'lib/block_repeater/exception_response.rb', line 6 def behaviour @behaviour end |
#response ⇒ Object
Returns the value of attribute response.
6 7 8 |
# File 'lib/block_repeater/exception_response.rb', line 6 def response @response end |
#types ⇒ Object
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 |