briefly 0.1.0 → 0.2.1

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.
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Briefly
4
- # An ordered list of +rescue_from+ registrations, queried at dispatch time.
5
- #
6
- # Entries are stored oldest-first and returned newest-first, so the most recent registration for a
7
- # given error class wins. Reads are lock-free against a frozen array; writes rebind it under a
8
- # mutex, because rebinding alone would drop concurrent registrations.
9
- class ErrorRegistry
10
- # A single registration. +names+ is +nil+ for facade-wide/global handlers.
11
- Entry = Struct.new(:klass, :names, :handler)
12
-
13
- def initialize
14
- @entries = [].freeze
15
- @mutex = Mutex.new
16
- end
17
-
18
- # @param klass [Class] matched against the raised error and its subclasses
19
- # @param names [Array<Symbol>, nil] canonical shortcut names, or +nil+ for every shortcut
20
- # @param handler [Proc] called with +(error, shortcut_name)+
21
- # @return [self]
22
- def add(klass, names, handler)
23
- @mutex.synchronize { @entries = [*@entries, Entry.new(klass, names&.freeze, handler)].freeze }
24
- self
25
- end
26
-
27
- # @param name [Symbol] a canonical shortcut name
28
- # @return [Array<Entry>] handlers scoped to +name+, most recently registered first
29
- def scoped(name) = @entries.reverse_each.select { |entry| entry.names&.include?(name) }
30
-
31
- # @return [Array<Entry>] handlers scoped to no shortcut in particular, most recent first
32
- def wide = @entries.reverse_each.select { |entry| entry.names.nil? }
33
-
34
- # @return [self]
35
- def clear
36
- @mutex.synchronize { @entries = [].freeze }
37
- self
38
- end
39
- end
40
- end
@@ -1,22 +0,0 @@
1
- module Briefly
2
- # An ordered list of `rescue_from` registrations, queried at dispatch time.
3
- class ErrorRegistry
4
- # A single registration. `names` is nil for facade-wide/global handlers.
5
- class Entry < ::Struct[untyped]
6
- attr_accessor klass: Class
7
- attr_accessor names: Array[Symbol]?
8
- attr_accessor handler: Briefly::handler
9
-
10
- def self.new: (Class klass, Array[Symbol]? names, Briefly::handler handler) -> Entry
11
- end
12
-
13
- @entries: Array[Entry]
14
- @mutex: Thread::Mutex
15
-
16
- def initialize: () -> void
17
- def add: (Class klass, Array[Symbol]? names, Briefly::handler handler) -> self
18
- def scoped: (Symbol name) -> Array[Entry]
19
- def wide: () -> Array[Entry]
20
- def clear: () -> self
21
- end
22
- end