Class: ServiceBureau::Locations

Inherits:
Object
  • Object
show all
Defined in:
lib/service_bureau/locations.rb

Overview

Stores the factories for all the configured services

Class Method Summary collapse

Class Method Details

.clearHash

Removes all the registered services.

Returns:

  • (Hash)

    the empty factory_map



34
35
36
# File 'lib/service_bureau/locations.rb', line 34

def clear
  factory_map.clear
end

.configure { ... } ⇒ Object

Configures the factories for each service

Each service should be configured with an object that responds to ‘call’

Examples:

ServiceBureau::Locations.configure do |c|
  c.my_service MyService.public_method(:new)
  c.other_service ->(arg){ OtherService.new(arg) }
end

Yields:

  • ServiceBureau::Locations

Yield Returns:

  • nothing

Returns:

  • nothing



19
20
21
# File 'lib/service_bureau/locations.rb', line 19

def configure(&block)
  yield self
end

.factory_mapHash

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.

Gets the map of service keys to factories.

Returns:

  • (Hash)

    mapping service keys to factories



27
28
29
# File 'lib/service_bureau/locations.rb', line 27

def factory_map
  @factory_map ||= {}
end

.method_missing(method_name, *args, &block) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/service_bureau/locations.rb', line 39

def method_missing(method_name, *args, &block)
  if args.size == 1 && !block_given?
    factory_map[method_name] = args.first
  else
    super
  end
end