diff options
-rw-r--r-- | Gemfile | 5 | ||||
-rw-r--r-- | Gemfile.lock | 14 | ||||
-rw-r--r-- | config/initializers/flipper.rb | 24 | ||||
-rw-r--r-- | lib/feature.rb | 9 |
4 files changed, 32 insertions, 20 deletions
@@ -405,8 +405,9 @@ gem 'gitaly-proto', '~> 0.59.0', require: 'gitaly' gem 'toml-rb', '~> 0.3.15', require: false # Feature toggles -gem 'flipper', '~> 0.10.2' -gem 'flipper-active_record', '~> 0.10.2' +gem 'flipper', '~> 0.11.0' +gem 'flipper-active_record', '~> 0.11.0' +gem 'flipper-active_support_cache_store', '~> 0.11.0' # Structured logging gem 'lograge', '~> 0.5' diff --git a/Gemfile.lock b/Gemfile.lock index efae71efdb7..f2546efa906 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -215,10 +215,13 @@ GEM path_expander (~> 1.0) ruby_parser (~> 3.0) sexp_processor (~> 4.0) - flipper (0.10.2) - flipper-active_record (0.10.2) + flipper (0.11.0) + flipper-active_record (0.11.0) activerecord (>= 3.2, < 6) - flipper (~> 0.10.2) + flipper (~> 0.11.0) + flipper-active_support_cache_store (0.11.0) + activesupport (>= 3.2, < 6) + flipper (~> 0.11.0) flowdock (0.7.1) httparty (~> 0.7) multi_json @@ -1021,8 +1024,9 @@ DEPENDENCIES faraday (~> 0.12) ffaker (~> 2.4) flay (~> 2.8.0) - flipper (~> 0.10.2) - flipper-active_record (~> 0.10.2) + flipper (~> 0.11.0) + flipper-active_record (~> 0.11.0) + flipper-active_support_cache_store (~> 0.11.0) fog-aliyun (~> 0.2.0) fog-aws (~> 1.4) fog-core (~> 1.44) diff --git a/config/initializers/flipper.rb b/config/initializers/flipper.rb index bfab8c77a4b..cc9167d29b9 100644 --- a/config/initializers/flipper.rb +++ b/config/initializers/flipper.rb @@ -1,8 +1,22 @@ -require 'flipper/middleware/memoizer' +require 'flipper/adapters/active_record' +require 'flipper/adapters/active_support_cache_store' -unless Rails.env.test? - Rails.application.config.middleware.use Flipper::Middleware::Memoizer, - lambda { Feature.flipper } +Flipper.configure do |config| + config.default do + adapter = Flipper::Adapters::ActiveRecord.new( + feature_class: Feature::FlipperFeature, gate_class: Feature::FlipperGate) + cached_adapter = Flipper::Adapters::ActiveSupportCacheStore.new( + adapter, + Rails.cache, + expires_in: 10.seconds) + + Flipper.new(cached_adapter) + end +end - Feature.register_feature_groups +Feature.register_feature_groups + +unless Rails.env.test? + require 'flipper/middleware/memoizer' + Rails.application.config.middleware.use Flipper::Middleware::Memoizer end diff --git a/lib/feature.rb b/lib/feature.rb index ac3bc65c0d5..8e9ba5c530a 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -1,5 +1,3 @@ -require 'flipper/adapters/active_record' - class Feature # Classes to override flipper table names class FlipperFeature < Flipper::Adapters::ActiveRecord::Feature @@ -62,12 +60,7 @@ class Feature end def flipper - @flipper ||= begin - adapter = Flipper::Adapters::ActiveRecord.new( - feature_class: FlipperFeature, gate_class: FlipperGate) - - Flipper.new(adapter) - end + @flipper ||= Flipper.instance end # This method is called from config/initializers/flipper.rb and can be used |