class StubRequests::ServiceRegistry

Class Registry provides registration of services

@author Mikael Henriksson <mikael@zoolutions.se>

Attributes

services[R]

@!attribute [rw] services

@return [Concurrent::Map<Symbol, Service>] a map with services

Public Class Methods

new() click to toggle source

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

count()
Alias for: size
find(service_id) click to toggle source

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
find!(service_id) click to toggle source

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
register(service_id, service_uri) click to toggle source

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
remove(service_id) click to toggle source

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
reset() click to toggle source

Resets the map with registered services

@api private

# File lib/stub_requests/service_registry.rb, line 58
def reset
  services.clear
end
size() click to toggle source

Returns the size of the registry

@return [Integer]

# File lib/stub_requests/service_registry.rb, line 48
def size
  keys.size
end
Also aliased as: count