Last active
May 12, 2020 09:06
-
-
Save thejonanshow/2dc9e18a0e2c0a568dbab43f051692d2 to your computer and use it in GitHub Desktop.
Justin wants to take Rails off the rails...
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
require "rack" | |
class Application | |
def call(env) | |
status = 200 | |
headers = { "Content-Type" => "text/html" } | |
body = ["<h1>WHY?</h1>"] | |
[status, headers, body] | |
end | |
end | |
class First | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
body1 = Second.new(@app).call(env).last | |
body2 = AlsoSecond.new(@app).call(env).last | |
status, headers, body = @app.call(env) | |
[status, headers, body2 + body1 + body] | |
end | |
end | |
class Second | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
status, headers, body = @app.call(env) | |
[status, headers, ["<h2>Why Justin</h2>"]] | |
end | |
end | |
class AlsoSecond | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
status, headers, body = @app.call(env) | |
[status, headers, ["<h3>WHY?</h3>"]] | |
end | |
end | |
use First | |
run Application.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment