mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
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.
22 lines
443 B
Ruby
22 lines
443 B
Ruby
module OpenFoodNetwork
|
|
class FeatureToggle
|
|
def self.enabled?(feature_name)
|
|
true?(env_variable_value(feature_name))
|
|
end
|
|
|
|
private
|
|
|
|
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
|