Class: Synchronisable::ErrorHandler Private

Inherits:
Object
  • Object
show all
Defined in:
lib/synchronisable/error_handler.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Helper class for synchronization errors handling.

See Also:

Instance Method Summary collapse

Constructor Details

#initialize(logger, context) ⇒ ErrorHandler

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ErrorHandler.

Parameters:


10
11
12
# File 'lib/synchronisable/error_handler.rb', line 10

def initialize(logger, context)
  @logger, @context = logger, context
end

Instance Method Details

#handle(source) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Wraps the given block in transaction if it's source for a model on which #sync method was called and not a parent/child association. Rescued exceptions are written to log and saved to the errors array.

Parameters:

Returns:

  • (Boolean)

    `true` if syncronization was completed without errors, `false` otherwise


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/synchronisable/error_handler.rb', line 22

def handle(source)
  invoke(source) do
    yield
    return true
  end
rescue SystemExit, Interrupt
  raise
rescue Exception => e
  err_msg = error_message(e, source)

  @context.errors << err_msg
  @logger.error err_msg

  return false
end