Class: Flipflop::FeatureCache::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/flipflop/feature_cache.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



4
5
6
# File 'lib/flipflop/feature_cache.rb', line 4

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/flipflop/feature_cache.rb', line 8

def call(env)
  return @app.call(env) if FeatureCache.current.enabled?

  FeatureCache.current.enable!
  response = @app.call(env)
  response[2] = Rack::BodyProxy.new(response[2]) do
    FeatureCache.current.disable!
  end
  response
rescue Exception => err
  FeatureCache.current.disable!
  raise err
end