Class: Protocol::HTTP::Middleware::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/protocol/http/middleware/builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(default_app = NotFound) ⇒ Builder

Returns a new instance of Builder.


38
39
40
41
# File 'lib/protocol/http/middleware/builder.rb', line 38

def initialize(default_app = NotFound)
	@use = []
	@app = default_app
end

Instance Method Details

#run(app) ⇒ Object


49
50
51
# File 'lib/protocol/http/middleware/builder.rb', line 49

def run(app)
	@app = app
end

#to_appObject


53
54
55
# File 'lib/protocol/http/middleware/builder.rb', line 53

def to_app
	@use.reverse.inject(@app) {|app, use| use.call(app)}
end

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


43
44
45
# File 'lib/protocol/http/middleware/builder.rb', line 43

def use(middleware, *arguments, &block)
	@use << proc {|app| middleware.new(app, *arguments, &block)}
end