Class: ConfigurationService::ProviderRegistry

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

Overview

A singleton registry of configuration service providers

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceConfigurationService::ProviderRegistry

The singleton registry instance

Returns:



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
# File 'lib/configuration_service/provider_registry.rb', line 15

class ProviderRegistry

  include Singleton

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

    ##
    # Look up a configuration service provider
    #
    # @param [String] identifier
    #   the unique identifier for the configuration service provider.
    #   The provider must already have been registered with {#register}.
    #
    # @return [Class] the configuration service provider class
    # @return [nil] if no provider has been registered with the given +identifier+
    #
    def lookup(identifier)
      @providers[identifier]
    end

    # @private
    def initialize
      @providers = {}
    end

end

Instance Method Details

#lookup(identifier) ⇒ Class?

Look up a configuration service provider

Parameters:

  • identifier (String)

    the unique identifier for the configuration service provider. The provider must already have been registered with #register.

Returns:

  • (Class)

    the configuration service provider class

  • (nil)

    if no provider has been registered with the given identifier



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

def lookup(identifier)
  @providers[identifier]
end

#register(identifier, provider) ⇒ Object

Register a configuration service provider

Parameters:

  • identifier (String)

    unique identifier for the configuration service provider

  • provider (Class)

    the configuration service provider class



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

def register(identifier, provider)
  @providers[identifier] = provider
end