Class: ConfigurationService::Factory::EnvironmentContext
- Inherits:
-
Object
- Object
- ConfigurationService::Factory::EnvironmentContext
- Includes:
- BackwardCompatibility
- Defined in:
- lib/configuration_service/factory/environment_context.rb,
lib/configuration_service/factory/environment_context/env_dict.rb,
lib/configuration_service/factory/environment_context/backward_compatibility.rb
Overview
A factory context for the process ENV and (on JRuby) system properties
Most consumers will not need to interact with this class directly. It is used by ConfigurationService::Factory to create the default factory context if none is specified.
Prior to version 2.2.0, this class provided factory functionality. Use of this class as a factory is deprecated, supported through the BackwardCompatibility module. Consumers should use ConfigurationService::Factory instead.
Defined Under Namespace
Modules: BackwardCompatibility Classes: EnvDict
Constant Summary collapse
- DEFAULT_PREFIX =
The default prefix for matching environment variable names
"CFGSRV"
Instance Attribute Summary collapse
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Instance Method Summary collapse
- #identifier ⇒ Object
-
#initialize(sources = default_sources, prefix = DEFAULT_PREFIX) ⇒ EnvironmentContext
constructor
Returns a new factory context.
- #provider_config ⇒ Object
- #provider_id ⇒ Object
-
#scrub! ⇒ Object
Scrub sources.
- #token ⇒ Object
Methods included from BackwardCompatibility
Constructor Details
#initialize(sources = default_sources, prefix = DEFAULT_PREFIX) ⇒ EnvironmentContext
Returns a new factory context
The sources are scanned for #prefix matches, within which the following variables are used:
- IDENTIFIER
-
the unique identity of the configuration data (see Base#initialize)
- TOKEN
-
authorization token for the identified configuration data (see Base#initialize)
- PROVIDER
-
the unique identity of the service provider (see ProviderRegistry)
- PROVIDER_*
-
configuration options for the service provider (see service provider documentation)
If sources are not specified, the process ENV and (on JRuby) system properties are used. Where a system property and environment variable of the same name exist, the environment variable is preferred.
53 54 55 |
# File 'lib/configuration_service/factory/environment_context.rb', line 53 def initialize(sources = default_sources, prefix = DEFAULT_PREFIX) @env = EnvDict.new(sources, prefix) end |
Instance Attribute Details
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
23 24 25 |
# File 'lib/configuration_service/factory/environment_context.rb', line 23 def prefix @prefix end |
Instance Method Details
#identifier ⇒ Object
59 60 61 |
# File 'lib/configuration_service/factory/environment_context.rb', line 59 def identifier @env[:identifier] end |
#provider_config ⇒ Object
77 78 79 |
# File 'lib/configuration_service/factory/environment_context.rb', line 77 def provider_config @env.subslice(:provider) end |
#provider_id ⇒ Object
71 72 73 |
# File 'lib/configuration_service/factory/environment_context.rb', line 71 def provider_id @env[:provider] end |
#scrub! ⇒ Object
Scrub sources
Called by the ConfigurationService::Factory after the client is created, to prevent in-process compromise of the context (e.g. by an exception handler that dumps the environment in a web application).
Every property that matches the prefix is removed from all sources.
90 91 92 |
# File 'lib/configuration_service/factory/environment_context.rb', line 90 def scrub! @env.scrub! end |
#token ⇒ Object
65 66 67 |
# File 'lib/configuration_service/factory/environment_context.rb', line 65 def token @env[:token] end |