Class: Briefly::ErrorRegistry
- Inherits:
-
Object
- Object
- Briefly::ErrorRegistry
- Defined in:
- lib/briefly/error_registry.rb
Overview
An ordered list of rescue_from registrations, queried at dispatch time.
Entries are stored oldest-first and returned newest-first, so the most recent registration for a given error class wins. Reads are lock-free against a frozen array; writes rebind it under a mutex, because rebinding alone would drop concurrent registrations.
Defined Under Namespace
Classes: Entry
Instance Method Summary collapse
- #add(klass, names, handler) ⇒ self
- #clear ⇒ self
-
#initialize ⇒ ErrorRegistry
constructor
A new instance of ErrorRegistry.
-
#scoped(name) ⇒ Array<Entry>
Handlers scoped to
name, most recently registered first. -
#wide ⇒ Array<Entry>
Handlers scoped to no shortcut in particular, most recent first.
Constructor Details
#initialize ⇒ ErrorRegistry
Returns a new instance of ErrorRegistry.
13 14 15 16 |
# File 'lib/briefly/error_registry.rb', line 13 def initialize @entries = [].freeze @mutex = Mutex.new end |
Instance Method Details
#add(klass, names, handler) ⇒ self
22 23 24 25 |
# File 'lib/briefly/error_registry.rb', line 22 def add(klass, names, handler) @mutex.synchronize { @entries = [*@entries, Entry.new(klass, names&.freeze, handler)].freeze } self end |
#clear ⇒ self
35 36 37 38 |
# File 'lib/briefly/error_registry.rb', line 35 def clear @mutex.synchronize { @entries = [].freeze } self end |
#scoped(name) ⇒ Array<Entry>
Returns handlers scoped to name, most recently registered first.
29 |
# File 'lib/briefly/error_registry.rb', line 29 def scoped(name) = @entries.reverse_each.select { |entry| entry.names&.include?(name) } |
#wide ⇒ Array<Entry>
Returns handlers scoped to no shortcut in particular, most recent first.
32 |
# File 'lib/briefly/error_registry.rb', line 32 def wide = @entries.reverse_each.select { |entry| entry.names.nil? } |