Class: HttpMonkey::Configuration::Middlewares

Inherits:
Object
  • Object
show all
Defined in:
lib/http_monkey/configuration/middlewares.rb

Overview

Heavily inspired on Rack::Builder (rack.rubyforge.org/doc/Rack/Builder.html)

Instance Method Summary collapse

Constructor Details

#initializeMiddlewares

Returns a new instance of Middlewares.



6
7
8
9
# File 'lib/http_monkey/configuration/middlewares.rb', line 6

def initialize
  @chain = []
  @stack_middlewares = nil
end

Instance Method Details

#execute(app, env) ⇒ Object



23
24
25
26
# File 'lib/http_monkey/configuration/middlewares.rb', line 23

def execute(app, env)
  stacked = stack_middlewares(app, @chain)
  stacked.call(env)
end

#initialize_copy(source) ⇒ Object



11
12
13
14
15
# File 'lib/http_monkey/configuration/middlewares.rb', line 11

def initialize_copy(source)
  super
  @chain = @chain.clone
  @stack_middlewares = @stack_middlewares.clone if @stack_middlewares
end

#use(middleware, *args, &block) ⇒ Object



17
18
19
20
21
# File 'lib/http_monkey/configuration/middlewares.rb', line 17

def use(middleware, *args, &block)
  @chain << lambda { |app| middleware.new(app, *args, &block) }
  @stack_middlewares = nil
  self
end