Skip to content

Instantly share code, notes, and snippets.

@thejonanshow
Last active May 12, 2020 09:06
Show Gist options
  • Save thejonanshow/2dc9e18a0e2c0a568dbab43f051692d2 to your computer and use it in GitHub Desktop.
Save thejonanshow/2dc9e18a0e2c0a568dbab43f051692d2 to your computer and use it in GitHub Desktop.

Revisions

  1. thejonanshow revised this gist May 12, 2020. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions config.ru
    Original file line number Diff line number Diff line change
    @@ -19,9 +19,8 @@ class First
    body1 = Second.new(@app).call(env).last
    body2 = AlsoSecond.new(@app).call(env).last

    @app.call(env).tap do |result|
    result[-1] = [body2, body1, result.last].flatten
    end
    status, headers, body = @app.call(env)
    [status, headers, body2 + body1 + body]
    end
    end

  2. thejonanshow renamed this gist May 12, 2020. 1 changed file with 8 additions and 7 deletions.
    15 changes: 8 additions & 7 deletions middleware.rb → config.ru
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ class Application
    def call(env)
    status = 200
    headers = { "Content-Type" => "text/html" }
    body = ["WE DID IT! WHY?"]
    body = ["<h1>WHY?</h1>"]

    [status, headers, body]
    end
    @@ -16,11 +16,12 @@ def initialize(app)
    end

    def call(env)
    status, headers, body1 = Second.new(@app).call(env)
    status, headers, body2 = AlsoSecond.new(@app).call(env)
    status, headers, body0 = @app.call(env)
    body1 = Second.new(@app).call(env).last
    body2 = AlsoSecond.new(@app).call(env).last

    [status, headers, body0 + body1 + body2]
    @app.call(env).tap do |result|
    result[-1] = [body2, body1, result.last].flatten
    end
    end
    end

    @@ -31,7 +32,7 @@ def initialize(app)

    def call(env)
    status, headers, body = @app.call(env)
    [status, headers, ["\tSecond"]]
    [status, headers, ["<h2>Why Justin</h2>"]]
    end
    end

    @@ -42,7 +43,7 @@ def initialize(app)

    def call(env)
    status, headers, body = @app.call(env)
    [status, headers, ["\tAlsoSecond"]]
    [status, headers, ["<h3>WHY?</h3>"]]
    end
    end

  3. thejonanshow created this gist May 12, 2020.
    50 changes: 50 additions & 0 deletions middleware.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    require "rack"

    class Application
    def call(env)
    status = 200
    headers = { "Content-Type" => "text/html" }
    body = ["WE DID IT! WHY?"]

    [status, headers, body]
    end
    end

    class First
    def initialize(app)
    @app = app
    end

    def call(env)
    status, headers, body1 = Second.new(@app).call(env)
    status, headers, body2 = AlsoSecond.new(@app).call(env)
    status, headers, body0 = @app.call(env)

    [status, headers, body0 + body1 + body2]
    end
    end

    class Second
    def initialize(app)
    @app = app
    end

    def call(env)
    status, headers, body = @app.call(env)
    [status, headers, ["\tSecond"]]
    end
    end

    class AlsoSecond
    def initialize(app)
    @app = app
    end

    def call(env)
    status, headers, body = @app.call(env)
    [status, headers, ["\tAlsoSecond"]]
    end
    end

    use First
    run Application.new