Class: StubRequests::ServiceRegistry
- Includes:
- Enumerable, Singleton
- Defined in:
- lib/stub_requests/service_registry.rb
Overview
Class ServiceRegistry provides registration of services
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#each { ... } ⇒ Concurrent::Map<Symbol, Service>
Required by Enumerable.
-
#get_service(service_id) ⇒ Service
Fetches a service from the registry.
-
#get_service!(service_id) ⇒ Endpoint
Fetches a service from the registry or raises ServiceNotFound.
-
#initialize ⇒ ServiceRegistry
constructor
A new instance of ServiceRegistry.
-
#register_service(service_id, service_uri) ⇒ Service
Registers a service in the registry.
-
#remove_service(service_id) ⇒ Object
Removes a service from the registry.
-
#reset ⇒ Object
private
Resets the map with registered services.
Constructor Details
#initialize ⇒ ServiceRegistry
Returns a new instance of ServiceRegistry
25 26 27 |
# File 'lib/stub_requests/service_registry.rb', line 25 def initialize @services = Concurrent::Map.new end |
Instance Attribute Details
#services ⇒ Object
23 24 25 |
# File 'lib/stub_requests/service_registry.rb', line 23 def services @services end |
Instance Method Details
#each { ... } ⇒ Concurrent::Map<Symbol, Service>
Required by Enumerable
46 47 48 |
# File 'lib/stub_requests/service_registry.rb', line 46 def each(&block) services.each(&block) end |
#get_service(service_id) ⇒ Service
Fetches a service from the registry
87 88 89 |
# File 'lib/stub_requests/service_registry.rb', line 87 def get_service(service_id) services[service_id] end |
#get_service!(service_id) ⇒ Endpoint
Fetches a service from the registry or raises StubRequests::ServiceNotFound
101 102 103 |
# File 'lib/stub_requests/service_registry.rb', line 101 def get_service!(service_id) get_service(service_id) || raise(ServiceNotFound, service_id) end |
#register_service(service_id, service_uri) ⇒ Service
Registers a service in the registry
59 60 61 62 63 64 65 |
# File 'lib/stub_requests/service_registry.rb', line 59 def register_service(service_id, service_uri) if (service = get_service(service_id)) StubRequests.logger.warn("Service already registered #{service}") raise ServiceHaveEndpoints, service if service.endpoints? end services[service_id] = Service.new(service_id, service_uri) end |
#remove_service(service_id) ⇒ Object
Removes a service from the registry
75 76 77 |
# File 'lib/stub_requests/service_registry.rb', line 75 def remove_service(service_id) services.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
34 35 36 |
# File 'lib/stub_requests/service_registry.rb', line 34 def reset services.clear end |