Class: StateFlow::ExceptionHandler

Inherits:
Event show all
Defined in:
lib/state_flow/exception_handler.rb

Instance Attribute Summary collapse

Attributes inherited from Element

#destination, #origin

Instance Method Summary collapse

Methods included from ExceptionHandlerClient

#exception_handlers, #exception_handling

Methods included from ActionClient

#action

Methods included from GuardClient

#guard, #guard_else, #guard_for, #guards

Methods inherited from Element

#flow, #inspect, #retry_in_recovering, #state, #to, uninspected_var, uninspected_vars, #update_to_destination

Methods included from ElementVisitable

#visit

Constructor Details

#initialize(origin, *exceptions, &block) ⇒ ExceptionHandler

Returns a new instance of ExceptionHandler.



9
10
11
12
13
14
15
16
17
18
# File 'lib/state_flow/exception_handler.rb', line 9

def initialize(origin, *exceptions, &block)
  options = exceptions.extract_options!
  @exceptions = exceptions
  super(origin, &block)
  @recovering = options[:recovering] || false
  @rolling_back = options[:rolling_back] || options[:rollback] || false
  @logging_error = options[:logging]
  # 例外をハンドリングしている最中にエラーが出た場合にraiseするかどうか。デフォルトnil
  @raise_error_in_handling = options[:raise_error_in_handling] 
end

Instance Attribute Details

#exceptionsObject (readonly)

Returns the value of attribute exceptions.



6
7
8
# File 'lib/state_flow/exception_handler.rb', line 6

def exceptions
  @exceptions
end

#logging_errorObject (readonly)

Returns the value of attribute logging_error.



7
8
9
# File 'lib/state_flow/exception_handler.rb', line 7

def logging_error
  @logging_error
end

#raise_error_in_handlingObject (readonly)

Returns the value of attribute raise_error_in_handling.



7
8
9
# File 'lib/state_flow/exception_handler.rb', line 7

def raise_error_in_handling
  @raise_error_in_handling
end

#recoveringObject (readonly)

Returns the value of attribute recovering.



7
8
9
# File 'lib/state_flow/exception_handler.rb', line 7

def recovering
  @recovering
end

#rolling_backObject (readonly)

Returns the value of attribute rolling_back.



7
8
9
# File 'lib/state_flow/exception_handler.rb', line 7

def rolling_back
  @rolling_back
end

Instance Method Details

#match?(exception) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/state_flow/exception_handler.rb', line 20

def match?(exception)
  prepare_exceptions
  exceptions.any?{|klass| exception.is_a?(klass)}
end

#process(context) ⇒ Object



25
26
27
28
29
30
# File 'lib/state_flow/exception_handler.rb', line 25

def process(context)
  context.recovered_exceptions << context.exceptions.last if recovering
  context.record_reload_if_possible # rollbackよりもreloadが先じゃないとネストしたtransactionでおかしい場合がある?
  # context.transaction_rollback if rolling_back
  super
end