Skip to content

Commit 16bd889

Browse files
committedMay 10, 2021
Remove memoizer from api
If you aren't using default setup, you'll need to add this back in. ``` use Flipper::Api.app(flipper, env_key: "flipper_api") do |builder| builder.use Flipper::Api::Memoizer, flipper, env_key: "flipper_api" end ```
1 parent ad179d1 commit 16bd889

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed
 

‎lib/flipper/api.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ def self.app(flipper = nil, options = {})
1515
builder = Rack::Builder.new
1616
yield builder if block_given?
1717
builder.use Flipper::Api::JsonParams
18-
builder.use Flipper::Middleware::SetupEnv, flipper, env_key: env_key
19-
builder.use Flipper::Middleware::Memoizer, memoizer_options.merge(env_key: env_key)
20-
builder.use Flipper::Api::Middleware, env_key: env_key
18+
builder.use Flipper::Api::Middleware, flipper, env_key: env_key
2119
builder.run app
2220
klass = self
2321
builder.define_singleton_method(:inspect) { klass.inspect } # pretty rake routes output

‎lib/flipper/api/middleware.rb

+15-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@
99
module Flipper
1010
module Api
1111
class Middleware
12-
def initialize(app, options = {})
12+
def initialize(app, flipper = nil, options = {})
1313
@app = app
1414
@env_key = options.fetch(:env_key, 'flipper')
1515

16+
if flipper.respond_to?(:call)
17+
@flipper_block = flipper
18+
else
19+
@flipper = flipper || Flipper
20+
end
21+
1622
@action_collection = ActionCollection.new
1723
@action_collection.add Api::V1::Actions::PercentageOfTimeGate
1824
@action_collection.add Api::V1::Actions::PercentageOfActorsGate
@@ -32,13 +38,19 @@ def call(env)
3238
def call!(env)
3339
request = Rack::Request.new(env)
3440
action_class = @action_collection.action_for_request(request)
41+
3542
if action_class.nil?
3643
@app.call(env)
3744
else
38-
flipper = env.fetch(@env_key)
39-
action_class.run(flipper, request)
45+
action_class.run(env[@env_key] || flipper, request)
4046
end
4147
end
48+
49+
private
50+
51+
def flipper
52+
@flipper ||= @flipper_block.call
53+
end
4254
end
4355
end
4456
end

0 commit comments

Comments
 (0)
Please sign in to comment.