Class: StubRequests::ServiceRegistry
- Extended by:
- Forwardable
- Includes:
- Enumerable, Singleton
- Defined in:
- lib/stub_requests/service_registry.rb
Overview
Class Registry provides registration of services
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#find(service_id) ⇒ Service
Fetches a service from the registry.
-
#find!(service_id) ⇒ Service
Fetches a service from the registry or raises ServiceNotFound.
-
#initialize ⇒ ServiceRegistry
constructor
Initialize a new instance (used by Singleton).
-
#register(service_id, service_uri) ⇒ Service
Registers a service in the registry.
-
#remove(service_id) ⇒ Object
Removes a service from the registry.
-
#reset ⇒ Object
private
Resets the map with registered services.
-
#size ⇒ Integer
(also: #count)
Returns the size of the registry.
Constructor Details
#initialize ⇒ ServiceRegistry
Initialize a new instance (used by Singleton)
38 39 40 |
# File 'lib/stub_requests/service_registry.rb', line 38 def initialize @services = Concurrent::Map.new end |
Instance Attribute Details
#services ⇒ Object
32 33 34 |
# File 'lib/stub_requests/service_registry.rb', line 32 def services @services end |
Instance Method Details
#find(service_id) ⇒ Service
Fetches a service from the registry
99 100 101 |
# File 'lib/stub_requests/service_registry.rb', line 99 def find(service_id) self[service_id] end |
#find!(service_id) ⇒ Service
Fetches a service from the registry or raises StubRequests::ServiceNotFound
113 114 115 |
# File 'lib/stub_requests/service_registry.rb', line 113 def find!(service_id) self[service_id] || raise(ServiceNotFound, service_id) end |
#register(service_id, service_uri) ⇒ Service
Registers a service in the registry
71 72 73 74 75 76 77 |
# File 'lib/stub_requests/service_registry.rb', line 71 def register(service_id, service_uri) service = Service.new(service_id, service_uri) StubRequests.logger.warn("Service already registered #{service}") if self[service_id] self[service_id] = service service end |
#remove(service_id) ⇒ Object
Removes a service from the registry
87 88 89 |
# File 'lib/stub_requests/service_registry.rb', line 87 def remove(service_id) delete(service_id) || raise(ServiceNotFound, service_id) 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
58 59 60 |
# File 'lib/stub_requests/service_registry.rb', line 58 def reset services.clear end |
#size ⇒ Integer Also known as: count
Returns the size of the registry
48 49 50 |
# File 'lib/stub_requests/service_registry.rb', line 48 def size keys.size end |