Class: ConfigurationService::Provider::Stub

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

Overview

A stub ConfigurationService::Base service provider

Used to validate the test framework architecture.

Registered into the ProviderRegistry with identifier “stub”.

Constant Summary collapse

BUILTIN_TOKENS =

Maps roles to authorization tokens

{
  :consumer  => '64867ebd-6364-0bd3-3fda-81-requestor',
  :publisher => 'f53606cb-7f3c-4432-afe8-44-publisher',
  :nothing   => '2972abd7-b055-4841-8ad1-4a34-nothing',
}

Instance Method Summary collapse

Constructor Details

#initialize(name:) ⇒ Stub

Returns a new Stub

It requires an arbitrary name, used solely for testing factory methods.



36
37
38
39
# File 'lib/configuration_service/provider/stub.rb', line 36

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

Instance Method Details

#publish_configuration(configuration, token) ⇒ Object

Publishes configuration

See Base#publish_configuration.

configuration should be a Configuration object or similar.

Returns a Configuration object or raises an Error on failure.



70
71
72
73
74
# File 'lib/configuration_service/provider/stub.rb', line 70

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

#request_configuration(identifier, token) ⇒ Object

Requests configuration data and metadata

See Base#request_configuration.

Fetches configuration from the singleton StubStore.

Returns a Configuration object or raises AuthorizationError if the token is not for the :consumer role.

Returns nil if no configuration was found for the identifier.



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

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