class Togls::ToggleRepositoryDrivers::EnvOverrideDriver

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.

Public Instance Methods

get(toggle_id) click to toggle source
# 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) click to toggle source
# File lib/togls/toggle_repository_drivers/env_override_driver.rb, line 19
def store(toggle_id, toggle_data)
end

Private Instance Methods

toggle_env_key(toggle_id) click to toggle source
# File lib/togls/toggle_repository_drivers/env_override_driver.rb, line 37
def toggle_env_key(toggle_id)
  "TOGLS_#{toggle_id.to_s.upcase}"
end