Skip to content

Instantly share code, notes, and snippets.

@changmason
Created October 12, 2011 06:45
Show Gist options
  • Save changmason/1280467 to your computer and use it in GitHub Desktop.
Save changmason/1280467 to your computer and use it in GitHub Desktop.
rack middleware chaining
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
@changmason
Copy link
Author

A.new(B.new(C.new(app))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment