Created
October 12, 2011 06:45
-
-
Save changmason/1280467 to your computer and use it in GitHub Desktop.
rack middleware chaining
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class M | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
puts "Before call in middleware #{self.class}" | |
response = @app.call(env) | |
puts "After call in middleware #{self.class}" | |
response | |
end | |
end | |
class A < M | |
end | |
class B < M | |
end | |
class C < M | |
end | |
app = lambda do |env| | |
puts "I am the endpoint app" | |
[ | |
200, | |
{ "Content-Type" => "text/html" }, | |
["I'm the endpoint"] | |
] | |
end | |
use A | |
use B | |
use C | |
run app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A.new(B.new(C.new(app))))