Class: ServiceBureau::Locator
- Inherits:
-
Object
- Object
- ServiceBureau::Locator
- Defined in:
- lib/service_bureau/locator.rb
Overview
Finds service factories and instantiates services
Class Method Summary collapse
-
.get_service(service_key, *args) ⇒ Object
Finds a factory and instantiates a service.
Instance Method Summary collapse
-
#get_service(service_key, *args) ⇒ Object
Finds a factory and instantiates a service.
-
#initialize ⇒ Locator
constructor
Initializes a new Locator with the mapping of service keys to factories.
Constructor Details
#initialize ⇒ Locator
Initializes a new Locator with the mapping of service keys to factories.
5 6 7 |
# File 'lib/service_bureau/locator.rb', line 5 def initialize @service_factories = ServiceBureau::Locations.factory_map end |
Class Method Details
.get_service(service_key, *args) ⇒ Object
Finds a factory and instantiates a service
18 19 20 21 |
# File 'lib/service_bureau/locator.rb', line 18 def self.get_service service_key, *args @instance ||= new @instance.get_service service_key, *args end |
Instance Method Details
#get_service(service_key, *args) ⇒ Object
Finds a factory and instantiates a service
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/service_bureau/locator.rb', line 24 def get_service service_key, *args service_factories.fetch(service_key).call *args rescue KeyError raise UnknownServiceError.new("Cannot locate factory for '#{service_key}' - please check your configuration") rescue NoMethodError => err if err. =~ /undefined method `call'/ raise UncallableFactoryError.new("The factory registered for '#{service_key}' did not respond to #call") else raise end end |