Class: Exceptify::NotifierRegistry
- Inherits:
-
Object
- Object
- Exceptify::NotifierRegistry
- Defined in:
- lib/exceptify/notifier_registry.rb
Instance Attribute Summary collapse
-
#notifiers ⇒ Object
readonly
Returns the value of attribute notifiers.
Instance Method Summary collapse
- #clear ⇒ Object
- #copy ⇒ Object
- #fetch(name) ⇒ Object
-
#initialize(notifiers = {}, factory: nil) ⇒ NotifierRegistry
constructor
A new instance of NotifierRegistry.
- #names ⇒ Object
- #register(name, notifier_or_options) ⇒ Object
- #unregister(name) ⇒ Object
Constructor Details
#initialize(notifiers = {}, factory: nil) ⇒ NotifierRegistry
Returns a new instance of NotifierRegistry.
9 10 11 12 |
# File 'lib/exceptify/notifier_registry.rb', line 9 def initialize(notifiers = {}, factory: nil) @notifiers = notifiers.dup @factory = factory || method(:build_notifier) end |
Instance Attribute Details
#notifiers ⇒ Object (readonly)
Returns the value of attribute notifiers.
7 8 9 |
# File 'lib/exceptify/notifier_registry.rb', line 7 def notifiers @notifiers end |
Instance Method Details
#clear ⇒ Object
36 37 38 |
# File 'lib/exceptify/notifier_registry.rb', line 36 def clear notifiers.clear end |
#copy ⇒ Object
40 41 42 |
# File 'lib/exceptify/notifier_registry.rb', line 40 def copy self.class.new(notifiers, factory: @factory) end |
#fetch(name) ⇒ Object
28 29 30 |
# File 'lib/exceptify/notifier_registry.rb', line 28 def fetch(name) notifiers[name] end |
#names ⇒ Object
32 33 34 |
# File 'lib/exceptify/notifier_registry.rb', line 32 def names notifiers.keys end |
#register(name, notifier_or_options) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/exceptify/notifier_registry.rb', line 14 def register(name, ) if .respond_to?(:call) notifiers[name] = elsif .is_a?(Hash) notifiers[name] = @factory.call(name, ) else raise ArgumentError, "Invalid notifier '#{name}' defined as #{.inspect}" end end |
#unregister(name) ⇒ Object
24 25 26 |
# File 'lib/exceptify/notifier_registry.rb', line 24 def unregister(name) notifiers.delete(name) end |