Class: StubRequests::CallbackRegistry
- Extended by:
- Forwardable
- Includes:
- Enumerable, Singleton
- Defined in:
- lib/stub_requests/callback_registry.rb
Overview
Class Registry handles callbacks to webmock requests
Instance Attribute Summary collapse
- #callbacks ⇒ Object readonly
Instance Method Summary collapse
-
#initialize ⇒ CallbackRegistry
constructor
Used by Singleton.
-
#invoke_callbacks(request_stub) ⇒ void
Notifies subscribers that a request was made.
-
#register(service_id, endpoint_id, verb, block) ⇒ Callback
Register to a service endpoint call.
-
#reset ⇒ Object
private
Resets the map with registered services.
-
#unregister(service_id, endpoint_id, verb) ⇒ Callback
Unregister to a service endpoint call.
Constructor Details
#initialize ⇒ CallbackRegistry
Used by Singleton
39 40 41 |
# File 'lib/stub_requests/callback_registry.rb', line 39 def initialize @callbacks = Concurrent::Array.new end |
Instance Attribute Details
#callbacks ⇒ Object (readonly)
33 34 35 |
# File 'lib/stub_requests/callback_registry.rb', line 33 def callbacks @callbacks end |
Instance Method Details
#invoke_callbacks(request_stub) ⇒ void
This method returns an undefined value.
Notifies subscribers that a request was made
95 96 97 98 99 |
# File 'lib/stub_requests/callback_registry.rb', line 95 def invoke_callbacks(request_stub) return unless (callback = find_by(request_stub.service_id, request_stub.endpoint_id, request_stub.verb)) callback.call(request_stub) end |
#register(service_id, endpoint_id, verb, block) ⇒ Callback
Register to a service endpoint call
63 64 65 66 67 68 69 70 |
# File 'lib/stub_requests/callback_registry.rb', line 63 def register(service_id, endpoint_id, verb, block) callback = find_by(service_id, endpoint_id, verb) return callback if callback callback = Callback.new(service_id, endpoint_id, verb, block) callbacks.push(callback) callback end |
#reset ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Resets the map with registered services
48 49 50 |
# File 'lib/stub_requests/callback_registry.rb', line 48 def reset callbacks.clear end |
#unregister(service_id, endpoint_id, verb) ⇒ Callback
Unregister to a service endpoint call
82 83 84 85 86 |
# File 'lib/stub_requests/callback_registry.rb', line 82 def unregister(service_id, endpoint_id, verb) return unless (callback = find_by(service_id, endpoint_id, verb)) callbacks.delete(callback) end |