Class: ConfigurationService::DecoratorRegistry

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/configuration_service/decorator_registry.rb

Overview

A singleton registry of configuration service decorators

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceConfigurationService::DecoratorRegistry

The singleton registry instance



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/configuration_service/decorator_registry.rb', line 15

class DecoratorRegistry

  include Singleton

  ##
  # Register a configuration service decorator
  #
  # @param [String] identifier
  #   unique identifier for the configuration service decorator
  # @param [Class] decorator 
  #   the configuration service decorator class
  #
  def register(identifier, decorator)
    @decorators[identifier] = decorator 
  end

  ##
  # Look up a configuration service decorator 
  #
  # @param [String] identifier
  #   the unique identifier for the configuration service decorator.
  #   The decorator must already have been registered with {#register}.
  #
  # @return [Class] the configuration service decorator class
  # @return [nil] if no decorator has been registered with the given +identifier+
  #
  def lookup(identifier)
    raise ConfigurationService::DecoratorNotFoundError, "Decorator not found in registry" if not @decorators.key?(identifier)
    @decorators[identifier]
  end

  # @private
  def initialize
    @decorators = {}
  end

end

Instance Method Details

#lookup(identifier) ⇒ Class?

Look up a configuration service decorator



41
42
43
44
# File 'lib/configuration_service/decorator_registry.rb', line 41

def lookup(identifier)
  raise ConfigurationService::DecoratorNotFoundError, "Decorator not found in registry" if not @decorators.key?(identifier)
  @decorators[identifier]
end

#register(identifier, decorator) ⇒ Object

Register a configuration service decorator



27
28
29
# File 'lib/configuration_service/decorator_registry.rb', line 27

def register(identifier, decorator)
  @decorators[identifier] = decorator 
end