Class: Togls::ToggleRepositoryDrivers::EnvOverrideDriver
- Inherits:
-
Object
- Object
- Togls::ToggleRepositoryDrivers::EnvOverrideDriver
- Defined in:
- lib/togls/toggle_repository_drivers/env_override_driver.rb
Overview
Toggle Repository Environment Override Driver
The Toggle Repository Environment Override Driver provides a Toggle Repository driver that passively ignores requests to store toggles but still responds to retrieval requests. This conceptually makes it what I am referring to as an “Override Driver” because it only allows retrieving overrides from the store.
In this particular case it is an Environment Override Driver. Therefore, the store that backs this driver is environment variables. Specifically, this driver would retrieve a boolean rule initialized true if the associated environment variable was equal to the string, ‘true’. If the associated environment variable was equal to the string, ‘false’, it would return a boolean rule initialized to false. Any other value and the driver returns nil indicating that it couldn’t find the toggle in the store.
Instance Method Summary collapse
Instance Method Details
#get(toggle_id) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/togls/toggle_repository_drivers/env_override_driver.rb', line 22 def get(toggle_id) return nil if ENV[toggle_env_key(toggle_id)].nil? if ENV[toggle_env_key(toggle_id)] == 'true' return { 'feature_id' => toggle_id, 'rule_id' => Togls::Rules::Boolean.new(:on, :boolean, true).id.to_s } elsif ENV[toggle_env_key(toggle_id)] == 'false' return { 'feature_id' => toggle_id, 'rule_id' => Togls::Rules::Boolean.new(:off, :boolean, false).id.to_s } else return nil end end |
#store(toggle_id, toggle_data) ⇒ Object
19 20 |
# File 'lib/togls/toggle_repository_drivers/env_override_driver.rb', line 19 def store(toggle_id, toggle_data) end |