Sha256: 4c248154288ee1196e29d5032d520d1ed9e0b2ee1d5c0627a8155708aff2a47f

Contents?: true

Size: 1.74 KB

Versions: 32

Compression:

Stored size: 1.74 KB

Contents

require 'zlib'

require 'rack/request'
require 'rack/response'

module Rack
  # Paste has a Pony, Rack has a Lobster!
  class Lobster
    LobsterString = Zlib::Inflate.inflate("eJx9kEEOwyAMBO99xd7MAcytUhPlJyj2
    P6jy9i4k9EQyGAnBarEXeCBqSkntNXsi/ZCvC48zGQoZKikGrFMZvgS5ZHd+aGWVuWwhVF0
    t1drVmiR42HcWNz5w3QanT+2gIvTVCiE1lm1Y0eU4JGmIIbaKwextKn8rvW+p5PIwFl8ZWJ
    I8jyiTlhTcYXkekJAzTyYN6E08A+dk8voBkAVTJQ==".delete("\n ").unpack("m*")[0])

    LambdaLobster = lambda { |env|
      if env["QUERY_STRING"].include?("flip")
        lobster = LobsterString.split("\n").
          map { |line| line.ljust(42).reverse }.
          join("\n")
        href = "?"
      else
        lobster = LobsterString
        href = "?flip"
      end

      [200, {"Content-Type" => "text/html"},
       ["<title>Lobstericious!</title>",
        "<pre>", lobster, "</pre>",
        "<a href='#{href}'>flip!</a>"]
      ]
    }

    def call(env)
      req = Request.new(env)
      if req.GET["flip"] == "left"
        lobster = LobsterString.split("\n").
          map { |line| line.ljust(42).reverse }.
          join("\n")
        href = "?flip=right"
      elsif req.GET["flip"] == "crash"
        raise "Lobster crashed"
      else
        lobster = LobsterString
        href = "?flip=left"
      end

      Response.new.finish do |res|
        res.write "<title>Lobstericious!</title>"
        res.write "<pre>"
        res.write lobster
        res.write "</pre>"
        res.write "<p><a href='#{href}'>flip!</a></p>"
        res.write "<p><a href='?flip=crash'>crash!</a></p>"
      end
    end

  end
end

if $0 == __FILE__
  require 'rack'
  require 'rack/showexceptions'
  Rack::Handler::WEBrick.run \
    Rack::ShowExceptions.new(Rack::Lint.new(Rack::Lobster.new)),
    :Port => 9292
end

Version data entries

32 entries across 32 versions & 8 rubygems

Version Path
3mix-castronaut-0.5.0.2 vendor/rack/lib/rack/lobster.rb
masover-castronaut-0.4.4.4 vendor/rack/lib/rack/lobster.rb
masover-castronaut-0.4.4.5 vendor/rack/lib/rack/lobster.rb
masover-castronaut-0.5.0.1 vendor/rack/lib/rack/lobster.rb
relevance-castronaut-0.2.0 vendor/rack/lib/rack/lobster.rb
relevance-castronaut-0.2.5 vendor/rack/lib/rack/lobster.rb
relevance-castronaut-0.3.0 vendor/rack/lib/rack/lobster.rb
relevance-castronaut-0.3.5 vendor/rack/lib/rack/lobster.rb
relevance-castronaut-0.3.6 vendor/rack/lib/rack/lobster.rb
relevance-castronaut-0.4.1 vendor/rack/lib/rack/lobster.rb
relevance-castronaut-0.4.2 vendor/rack/lib/rack/lobster.rb
relevance-castronaut-0.4.3 vendor/rack/lib/rack/lobster.rb
relevance-castronaut-0.4.4 vendor/rack/lib/rack/lobster.rb
relevance-castronaut-0.4.5 vendor/rack/lib/rack/lobster.rb
relevance-castronaut-0.4.6 vendor/rack/lib/rack/lobster.rb
relevance-castronaut-0.5.0 vendor/rack/lib/rack/lobster.rb
relevance-castronaut-0.5.1 vendor/rack/lib/rack/lobster.rb
relevance-castronaut-0.5.2 vendor/rack/lib/rack/lobster.rb
relevance-castronaut-0.5.3 vendor/rack/lib/rack/lobster.rb
relevance-castronaut-0.5.4 vendor/rack/lib/rack/lobster.rb