Files
openfoodnetwork/lib/open_food_network/feature_toggle.rb
Maikel Linke 5d3dbca9c3 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.
2019-06-26 11:43:22 +10:00

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