Class: Exceptify::Rails::RunnerTie

Inherits:
Object
  • Object
show all
Defined in:
lib/exceptify/rails/runner_tie.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registrar: nil, error_source: nil, notifier: Exceptify) ⇒ RunnerTie

Returns a new instance of RunnerTie.



20
21
22
23
24
# File 'lib/exceptify/rails/runner_tie.rb', line 20

def initialize(registrar: nil, error_source: nil, notifier: Exceptify)
  @registrar = registrar || ->(&block) { at_exit(&block) }
  @error_source = error_source || -> { $ERROR_INFO }
  @notifier = notifier
end

Class Attribute Details

.installed=(value) ⇒ Object (writeonly)

Sets the attribute installed

Parameters:

  • value

    the value to set the attribute installed to.



9
10
11
# File 'lib/exceptify/rails/runner_tie.rb', line 9

def installed=(value)
  @installed = value
end

Class Method Details

.installed?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/exceptify/rails/runner_tie.rb', line 11

def installed?
  @installed == true
end

.reset!Object



15
16
17
# File 'lib/exceptify/rails/runner_tie.rb', line 15

def reset!
  @installed = false
end

Instance Method Details

#callObject

Registers an at_exit callback, which checks if there was an exception. This is a pretty crude way to detect exceptions from runner commands, but Rails doesn't provide a better API.

This should only be called from a runner callback in your Rails config; otherwise you may register the at_exit callback in more places than you need or want it.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/exceptify/rails/runner_tie.rb', line 31

def call
  return false if self.class.installed?

  self.class.installed = true

  @registrar.call do
    exception = @error_source.call
    if exception && !exception.is_a?(SystemExit)
      @notifier.notify_exception(exception, data: data_for_exceptify(exception))
    end
  end

  true
end