escalate 0.2.0.pre.3 → 0.2.0.pre.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67b615521fd3e15a59bb8401486496175afa19be36a98c415d9eccf52dd0815f
4
- data.tar.gz: 951d5afc0052cde73fca383e23dc38aa63e759fce7f4863b2093e9bf9b2463b4
3
+ metadata.gz: fc6bd15f68b37624979732a8c7b2c55d323c407c397c01ac59d8b8df54e90504
4
+ data.tar.gz: 144d6a67f62d9ca4ce7d740a26285dae283372450fd1149b74da59ab5411c982
5
5
  SHA512:
6
- metadata.gz: 7979594ec79d527e123efb08114d602ab11446d8e822a9a716b582150d7e0f4b97840443974270177d861d874fbf4544f7e14eb8bd5e98e66acc86d49b51e19a
7
- data.tar.gz: 2ab19d1367350559290fb9603e7af73934fcf1085121bf5a1cebe03059d450d19e53f76dc9947d92fac8a06f2a08fc0bb6ed12d0135a1e09617c87c6835dc158
6
+ metadata.gz: 1490795a292d531715525872a8bc06d1d27330222a24a436ad22ea62aa1d5fbc2e80b8a36b382cec86ef6281173bd5bddcbaffe9aa35c7f5bc641f6ac3611380
7
+ data.tar.gz: e2e7f3d6fd1be1e679bc6286c7fb892cef56fe64b57bbd55fedf649aa681c6e1d26f2f4f4aadbe8db3d0c327a378da65c46baee8fd20d137a6d6f1e2d40257d0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- escalate (0.2.0.pre.3)
4
+ escalate (0.2.0.pre.4)
5
5
  activesupport
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -78,6 +78,16 @@ Escalate.on_escalate do |exception, location_message, **context|
78
78
  end
79
79
  ```
80
80
 
81
+ #### Callback Uniqueness
82
+ Each callback may be named with the `name:` keyword argument.
83
+ If a callback with the same name has been registered before, it will be overwritten with the new one.
84
+ ```
85
+ Escalate.on_escalate(name: 'abc gem') do |exception, location_message, **context|
86
+ # send exception, location_message, **context to the error reporting service here
87
+ end
88
+ ```
89
+ If not given, the `name:` defaults to the `.source_location` property of the passed-in block.
90
+
81
91
  #### Handle the Logging in the `on_escalate` Callback
82
92
  Here is an example that handles logging itself with `log_first: false`:
83
93
  ```
data/lib/escalate.rb CHANGED
@@ -11,7 +11,7 @@ module Escalate
11
11
 
12
12
  LOG_FIRST_INSTANCE_VARIABLE = :@_escalate_log_first
13
13
 
14
- @on_escalate_callbacks = Set.new
14
+ @on_escalate_callbacks = {}
15
15
 
16
16
  class << self
17
17
  attr_reader :on_escalate_callbacks
@@ -31,7 +31,7 @@ module Escalate
31
31
  # Any additional context to be tied to the escalation
32
32
  def escalate(exception, location_message, logger, **context)
33
33
  ensure_failsafe("Exception rescued while escalating #{exception.inspect}") do
34
- if on_escalate_callbacks.none? || on_escalate_callbacks.any? { |block| block.instance_variable_get(LOG_FIRST_INSTANCE_VARIABLE) }
34
+ if on_escalate_callbacks.none? || on_escalate_callbacks.values.any? { |block| block.instance_variable_get(LOG_FIRST_INSTANCE_VARIABLE) }
35
35
  logger_allows_added_context?(logger) or context_string = " (#{context.inspect})"
36
36
  error_message = <<~EOS
37
37
  [Escalate] #{location_message}#{context_string}
@@ -46,7 +46,7 @@ module Escalate
46
46
  end
47
47
  end
48
48
 
49
- on_escalate_callbacks.each do |block|
49
+ on_escalate_callbacks.values.each do |block|
50
50
  ensure_failsafe("Exception rescued while escalating #{exception.inspect} to #{block.inspect}") do
51
51
  block.call(exception, location_message, **context)
52
52
  end
@@ -88,14 +88,17 @@ module Escalate
88
88
  end
89
89
  end
90
90
 
91
- # Registers an escalation callback to be executed when `escalate`
92
- # is invoked.
91
+ # Registers an escalation callback to be executed when `escalate` is invoked.
93
92
  #
94
93
  # @param [boolean] log_first: true
95
94
  # whether escalate should log first before escalating, or leave the logging to the escalate block
96
- def on_escalate(log_first: true, &block)
95
+ # @param [string | Array] name:
96
+ # unique name for this callback block
97
+ # any previously-registered block with the same name will be discarded
98
+ # if not provided, name defaults to `block.source_location`
99
+ def on_escalate(log_first: true, name: nil, &block)
97
100
  block.instance_variable_set(LOG_FIRST_INSTANCE_VARIABLE, log_first)
98
- on_escalate_callbacks.add(block)
101
+ on_escalate_callbacks[name || block.source_location] = block
99
102
  end
100
103
 
101
104
  def clear_on_escalate_callbacks
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Escalate
4
- VERSION = "0.2.0.pre.3"
4
+ VERSION = "0.2.0.pre.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: escalate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.pre.3
4
+ version: 0.2.0.pre.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca Development
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-03-01 00:00:00.000000000 Z
12
+ date: 2021-03-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport