Class: Async::HTTP::Middleware::Builder

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

Instance Method Summary collapse

Constructor Details

#initialize(default_app = NotFound, &block) ⇒ Builder

Returns a new instance of Builder.



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

def initialize(default_app = NotFound, &block)
	@use = []
	@app = default_app
	
	instance_eval(&block) if block_given?
end

Instance Method Details

#run(app) ⇒ Object



47
48
49
# File 'lib/async/http/middleware/builder.rb', line 47

def run(app)
	@app = app
end

#to_appObject



51
52
53
# File 'lib/async/http/middleware/builder.rb', line 51

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

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



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

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