Class: Exceptify::NotifierRegistry

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#notifiersObject (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

#clearObject



36
37
38
# File 'lib/exceptify/notifier_registry.rb', line 36

def clear
  notifiers.clear
end

#copyObject



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

#namesObject



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, notifier_or_options)
  if notifier_or_options.respond_to?(:call)
    notifiers[name] = notifier_or_options
  elsif notifier_or_options.is_a?(Hash)
    notifiers[name] = @factory.call(name, notifier_or_options)
  else
    raise ArgumentError, "Invalid notifier '#{name}' defined as #{notifier_or_options.inspect}"
  end
end

#unregister(name) ⇒ Object



24
25
26
# File 'lib/exceptify/notifier_registry.rb', line 24

def unregister(name)
  notifiers.delete(name)
end