mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-07 07:36:58 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user