Toggle features via env instead of initializer

A FeatureToggle could be switched via a class_eval in an initializer.
The initializer was installed via ofn-install. We want to get rid of
custom, untracked initializers. Here I'm changing the FeatureToggle
class to use environment variables instead.

This change needs to be followed up with a change in ofn-install to use
the new environment variable. It affects only Australian production.
This commit is contained in:
Maikel Linke
2019-06-25 17:25:21 +10:00
parent 723499332a
commit 5d3dbca9c3
2 changed files with 23 additions and 7 deletions

View File

@@ -1,13 +1,21 @@
module OpenFoodNetwork
class FeatureToggle
def self.enabled?(feature)
!!features.with_indifferent_access[feature]
def self.enabled?(feature_name)
true?(env_variable_value(feature_name))
end
private
def self.features
{ connect_learn_homepage: false }
def self.env_variable_value(feature_name)
ENV.fetch(env_variable_name(feature_name), nil)
end
def self.env_variable_name(feature_name)
"OFN_FEATURE_#{feature_name.to_s.upcase}"
end
def self.true?(value)
value.to_s.casecmp("true").zero?
end
end
end