class StubRequests::ServiceRegistry
Class
Registry provides registration of services
@author Mikael Henriksson <mikael@zoolutions.se>
Attributes
@!attribute [rw] services
@return [Concurrent::Map<Symbol, Service>] a map with services
Public Class Methods
Initialize a new instance (used by Singleton)
# File lib/stub_requests/service_registry.rb, line 38 def initialize @services = Concurrent::Map.new end
Public Instance Methods
Fetches a service from the registry
@param [Symbol] service_id id of the service to remove
@return [Service] the found service
# File lib/stub_requests/service_registry.rb, line 99 def find(service_id) self[service_id] end
Fetches a service from the registry or raises {ServiceNotFound}
@param [Symbol] service_id the id of a service
@raise [ServiceNotFound] when an endpoint couldn't be found
@return [Service]
# File lib/stub_requests/service_registry.rb, line 113 def find!(service_id) self[service_id] || raise(ServiceNotFound, service_id) end
Registers a service in the registry
@param [Symbol] service_id a symbolic id of the service @param [String] service_uri a string with a base_uri to the service
@return [Service] the service that was just registered
# 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
Removes a service from the registry
@param [Symbol] service_id the service_id to remove
@raise [ServiceNotFound] when the service was not removed
# File lib/stub_requests/service_registry.rb, line 87 def remove(service_id) delete(service_id) || raise(ServiceNotFound, service_id) end
Resets the map with registered services
@api private
# File lib/stub_requests/service_registry.rb, line 58 def reset services.clear end
Returns the size of the registry
@return [Integer]
# File lib/stub_requests/service_registry.rb, line 48 def size keys.size end