Class: Rack::PactBroker::UseWhen::ConditionallyUseMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/pact_broker/use_when.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, condition_proc, middleware, *args, &block) ⇒ ConditionallyUseMiddleware

Returns a new instance of ConditionallyUseMiddleware.



18
19
20
21
22
23
24
# File 'lib/rack/pact_broker/use_when.rb', line 18

def initialize(app, condition_proc, middleware, *args, &block)
  @app_without_middleware = app
  @condition_proc = condition_proc
  @middleware = middleware
  @args = args
  @block = block
end

Instance Method Details

#call(env) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/rack/pact_broker/use_when.rb', line 26

def call(env)
  if condition_proc.call(env)
    app_with_middleware.call(env)
  else
    app_without_middleware.call(env)
  end
end