Class: Pay::Webhooks::Delegator
- Inherits:
-
Object
- Object
- Pay::Webhooks::Delegator
- Defined in:
- lib/pay/webhooks/delegator.rb
Defined Under Namespace
Classes: NotificationAdapter
Instance Attribute Summary collapse
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
Instance Method Summary collapse
-
#all(callable = nil, &block) ⇒ Object
Listen to all events.
-
#configure(&block) ⇒ Object
Configure DSL.
-
#initialize ⇒ Delegator
constructor
A new instance of Delegator.
-
#instrument(event:, type:) ⇒ Object
Called to process an event.
- #listening?(type) ⇒ Boolean
-
#subscribe(name, callable = nil, &block) ⇒ Object
Subscribe to specific events.
-
#unsubscribe(name) ⇒ Object
Unsubscribe.
Constructor Details
#initialize ⇒ Delegator
Returns a new instance of Delegator.
6 7 8 |
# File 'lib/pay/webhooks/delegator.rb', line 6 def initialize @backend = ActiveSupport::Notifications end |
Instance Attribute Details
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
4 5 6 |
# File 'lib/pay/webhooks/delegator.rb', line 4 def backend @backend end |
Instance Method Details
#all(callable = nil, &block) ⇒ Object
Listen to all events
23 24 25 26 |
# File 'lib/pay/webhooks/delegator.rb', line 23 def all(callable = nil, &block) callable ||= block subscribe nil, callable end |
#configure(&block) ⇒ Object
Configure DSL
11 12 13 14 |
# File 'lib/pay/webhooks/delegator.rb', line 11 def configure(&block) raise ArgumentError, "must provide a block" unless block block.arity.zero? ? instance_eval(&block) : yield(self) end |
#instrument(event:, type:) ⇒ Object
Called to process an event
34 35 36 |
# File 'lib/pay/webhooks/delegator.rb', line 34 def instrument(event:, type:) backend.instrument name_with_namespace(type), event end |
#listening?(type) ⇒ Boolean
38 39 40 |
# File 'lib/pay/webhooks/delegator.rb', line 38 def listening?(type) backend.notifier.listening? name_with_namespace(type) end |
#subscribe(name, callable = nil, &block) ⇒ Object
Subscribe to specific events
17 18 19 20 |
# File 'lib/pay/webhooks/delegator.rb', line 17 def subscribe(name, callable = nil, &block) callable ||= block backend.subscribe to_regexp(name), NotificationAdapter.new(callable) end |
#unsubscribe(name) ⇒ Object
Unsubscribe
29 30 31 |
# File 'lib/pay/webhooks/delegator.rb', line 29 def unsubscribe(name) backend.unsubscribe name_with_namespace(name) end |