mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-26 20:56:48 +00:00
The admin UI shows only features which were added to the database. We always had to look up a feature's name add it manually before we could enable it. Now it will appear in the UI after some code asked if it was enabled. This only adds a database query once when the feature doesn't exist yet. The `feature.exist?` call only performs an in-memory lookup in the memoizer.
17 lines
409 B
Ruby
17 lines
409 B
Ruby
# frozen_string_literal: true
|
|
|
|
module OpenFoodNetwork
|
|
# Feature toggles are configured via Flipper.
|
|
#
|
|
# - config/initializers/flipper.rb
|
|
# - http://localhost:3000/admin/feature-toggle/features
|
|
#
|
|
module FeatureToggle
|
|
def self.enabled?(feature_name, user = nil)
|
|
feature = Flipper.feature(feature_name)
|
|
feature.add unless feature.exist?
|
|
feature.enabled?(user)
|
|
end
|
|
end
|
|
end
|