Class: ConfigurationService::Decorator::ReferenceResolver
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- ConfigurationService::Decorator::ReferenceResolver
- Defined in:
- lib/configuration_service/decorator/reference_resolver.rb
Overview
Resolves configuration identifier references in configuration data
This configuration service provider decorator affects the #request_configuration and #authorize_consumption provider methods to support configuration identifier references in configuration data.
Configuration identifier references are strings of the form
%{ configuration_idenfier }
The referenced configuration identifier must exist when #request_configuration or #authorize_consumption encounter it, and references may only appear as the String values of top-level or nested dictionary keys.
Defined Under Namespace
Classes: MissingReferenceError
Constant Summary collapse
- PATTERN =
The regular expression used to match configuration identifier references
/%{\s*([^\s]+)\s*}/
Instance Method Summary collapse
-
#authorize_consumption(identifier, credentials) ⇒ Object
Authorize consumption of consumption of configuration including referenced identifiers.
-
#initialize(provider) ⇒ ReferenceResolver
constructor
Creates a new reference resolver decorator.
-
#request_configuration(identifier, credentials) ⇒ Object
Resolve configuration identifier references in configuration data.
Constructor Details
#initialize(provider) ⇒ ReferenceResolver
Creates a new reference resolver decorator
93 94 95 96 |
# File 'lib/configuration_service/decorator/reference_resolver.rb', line 93 def initialize(provider) @provider = provider super end |
Instance Method Details
#authorize_consumption(identifier, credentials) ⇒ Object
Authorize consumption of consumption of configuration including referenced identifiers
The String values of the configuration data identified by identifier
are searched for configuration identifier references.
The returned credentials provide access not only to the given identifier
but also to all identifiers for which references were found in the search of the data.
126 127 128 129 130 131 |
# File 'lib/configuration_service/decorator/reference_resolver.rb', line 126 def (identifier, credentials) configuration = @provider.request_configuration(identifier, credentials) identifiers = configuration ? find_configuration_identifiers(configuration.data) : [] identifiers.unshift(identifier) @provider.(identifiers, credentials) end |
#request_configuration(identifier, credentials) ⇒ Object
Resolve configuration identifier references in configuration data
The String values of configuration data returned by the provider are searched for configuration identifier references.
Each reference is replaced with the configuration data identified by the referenced identifier. References are detected at any depth of a nested configuration dictionary, but reference resolving is not recursive.
108 109 110 111 112 113 114 |
# File 'lib/configuration_service/decorator/reference_resolver.rb', line 108 def request_configuration(identifier, credentials) configuration = @provider.request_configuration(identifier, credentials) if configuration resolved_configuration_data = resolve_configuration_data(configuration.data, credentials) ConfigurationService::Configuration.new(configuration.identifier, resolved_configuration_data, configuration.) end end |