File tree 2 files changed +16
-6
lines changed
2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -15,9 +15,7 @@ def self.app(flipper = nil, options = {})
15
15
builder = Rack ::Builder . new
16
16
yield builder if block_given?
17
17
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
21
19
builder . run app
22
20
klass = self
23
21
builder . define_singleton_method ( :inspect ) { klass . inspect } # pretty rake routes output
Original file line number Diff line number Diff line change 9
9
module Flipper
10
10
module Api
11
11
class Middleware
12
- def initialize ( app , options = { } )
12
+ def initialize ( app , flipper = nil , options = { } )
13
13
@app = app
14
14
@env_key = options . fetch ( :env_key , 'flipper' )
15
15
16
+ if flipper . respond_to? ( :call )
17
+ @flipper_block = flipper
18
+ else
19
+ @flipper = flipper || Flipper
20
+ end
21
+
16
22
@action_collection = ActionCollection . new
17
23
@action_collection . add Api ::V1 ::Actions ::PercentageOfTimeGate
18
24
@action_collection . add Api ::V1 ::Actions ::PercentageOfActorsGate
@@ -32,13 +38,19 @@ def call(env)
32
38
def call! ( env )
33
39
request = Rack ::Request . new ( env )
34
40
action_class = @action_collection . action_for_request ( request )
41
+
35
42
if action_class . nil?
36
43
@app . call ( env )
37
44
else
38
- flipper = env . fetch ( @env_key )
39
- action_class . run ( flipper , request )
45
+ action_class . run ( env [ @env_key ] || flipper , request )
40
46
end
41
47
end
48
+
49
+ private
50
+
51
+ def flipper
52
+ @flipper ||= @flipper_block . call
53
+ end
42
54
end
43
55
end
44
56
end
You can’t perform that action at this time.
0 commit comments