Class: Shamu::Features::EnvStore
- Inherits:
-
Services::Service
- Object
- Services::Service
- Shamu::Features::EnvStore
- Defined in:
- lib/shamu/features/env_store.rb
Overview
Expose a read-only runtime environment for consumption by the FeaturesService. By default blends a Rack env request headers (if using Rack) with the host env. The request env overrides the host.
When fetching, EnvStore will look for an X-Shamu-Features
header
sent in the HTTP request. It should be constructed using pack to
build a verifiable hash of feature settings.
If a rack value is not set, EnvStore will fall back to looking for the
toggle in the host's environment with the name TOGGLE_{ toggle name
upcased and underscored }
. For example buy_now/one_click
will look for
TOGGLE_BUY_NOW_ONE_CLICK
in the environment.
Constant Summary collapse
- RACK_ENV_KEY =
"HTTP_X_SHAMU_FEATURES".freeze
- RACK_PARAMS_KEY =
"shamu.features".freeze
- RACK_PARAMS_FEATURES_KEY =
"shamu.features.from_params".freeze
- RACK_HEADER_FEATURES_KEY =
"shamu.features.from_header".freeze
Dependencies collapse
-
#codec ⇒ ToggleCode
Code used to pack and unpack the features.
Class Method Summary collapse
-
.env_key_name(key) ⇒ String
The expected ENV key name for the given toggle name.
Instance Method Summary collapse
-
#fetch(key, &block) ⇒ Object
Fetch a value from the environment.
Methods inherited from Services::Service
#cache_for, #cached_lookup, #entity_list, #entity_lookup_list, #error, #find_by_lookup, #lazy_association, #lookup_association
Instance Attribute Details
#codec ⇒ ToggleCode
Returns code used to pack and unpack the features.
29 |
# File 'lib/shamu/features/env_store.rb', line 29 attr_dependency :codec, ToggleCodec |
Class Method Details
.env_key_name(key) ⇒ String
Returns the expected ENV key name for the given toggle name.
41 42 43 44 45 |
# File 'lib/shamu/features/env_store.rb', line 41 def self.env_key_name( key ) key = key.upcase key.tr! "/", "_" key end |
Instance Method Details
#fetch(key, &block) ⇒ Object
Fetch a value from the environment.
35 36 37 38 |
# File 'lib/shamu/features/env_store.rb', line 35 def fetch( key, &block ) return env_fetch( key, &block ) unless defined? Rack rack_params_fetch( key, &block ) end |