Class: ConfigurationService::Provider::Stub

Inherits:
Object
  • Object
show all
Defined in:
lib/configuration_service/provider/stub.rb

Overview

A stub configuration service provider

Used to validate the test framework architecture.

It is registered into the ConfigurationService::ProviderRegistry with identifier “stub”.

Constant Summary collapse

BUILTIN_TOKENS =
{
  :admin => 'b72b9ae7-3849-a335-67b6-administrator',
  :consumer  => '64867ebd-6364-0bd3-3fda-81-requestor',
  :publisher => 'f53606cb-7f3c-4432-afe8-44-publisher',
  :none   => '2972abd7-b055-4841-8ad1-4a34-nothing',
}

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Stub

Returns a new instance of Stub.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :name (String)

    arbitrary name, used solely for testing factory methods



34
35
36
37
# File 'lib/configuration_service/provider/stub.rb', line 34

def initialize(options = {})
  @name = options[:name] or raise ArgumentError, "missing required argument: name"
  @configurations = StubStore.instance
end

Instance Method Details

#authorize_consumption(identifier, credentials) ⇒ String

Authorizes consumption of configuration

Parameters:

  • identifier (String)

    of configuration to be consumed

  • credentials (String)

    that allow me to authorize consumption of the configuration

Returns:

  • (String)

    credentials allowing consumption of the configuration



90
91
92
93
# File 'lib/configuration_service/provider/stub.rb', line 90

def authorize_consumption(identifier, credentials)
  authorize_request(:admin, credentials)
  BUILTIN_TOKENS[:consumer]
end

#publish_configuration(configuration, credentials) ⇒ ConfigurationService::Configuration

Publish configuration

Parameters:

Returns:

Raises:

See Also:



76
77
78
79
80
# File 'lib/configuration_service/provider/stub.rb', line 76

def publish_configuration(configuration, credentials)
  authorize_request(:publisher, credentials) 
  @configurations.store(configuration.identifier, configuration.data.dup, configuration.)
  configuration
end

#request_configuration(identifier, credentials) ⇒ ConfigurationService::Configuration?

Request configuration

Fetches configuration from the singleton StubStore.

Parameters:

  • identifier (String)

    unique configuration identifier

  • credentials (String)

    token for authentication and authorization

Returns:

Raises:

See Also:



55
56
57
58
59
60
61
# File 'lib/configuration_service/provider/stub.rb', line 55

def request_configuration(identifier, credentials)
  authorize_request(:consumer, credentials)
  data,  = @configurations.fetch(identifier)
  Configuration.new(identifier, data, )
rescue KeyError
  nil
end