Initialize flipper with default value

- Use the ActiveRecord adapter
 - Use a middle to cache data through memoization (see https://github.com/jnunemaker/flipper/blob/master/docs/Optimization.md)
 - Create the group `admins`: only user which are admins
 - Create `unit_price` feature attached to `admins` group
 - Add method `flipper_id` on User
This commit is contained in:
Jean-Baptiste Bellet
2021-03-30 12:23:02 +02:00
parent ad71f925be
commit a4b53d6ac4
2 changed files with 20 additions and 0 deletions

View File

@@ -135,6 +135,10 @@ module Spree
spree_orders.incomplete.where(created_by_id: id).order('created_at DESC').first
end
def flipper_id
"#{self.class.name};#{id}"
end
protected
def password_required?

View File

@@ -0,0 +1,16 @@
require "flipper"
require "flipper/adapters/active_record"
Flipper.configure do |config|
config.default do
Flipper.new(Flipper::Adapters::ActiveRecord.new)
end
end
Rails.configuration.middleware.use Flipper::Middleware::Memoizer, preload_all: true
Flipper.register(:admins) { |actor| actor.respond_to?(:admin?) && actor.admin? }
if !Flipper[:unit_price].exist?
# Unit price default setup, could be overided by admin in the flipper-ui interface
Flipper.enable_group :unit_price, :admins
end