Sha256: 6220cfb8434eaeba8c812ca873b91cfdc412957e1cc3f5b83f4501549e4fba05

Contents?: true

Size: 1.84 KB

Versions: 249

Compression:

Stored size: 1.84 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

      content = ["<title>Lobstericious!</title>",
                 "<pre>", lobster, "</pre>",
                 "<a href='#{href}'>flip!</a>"]
      length = content.inject(0) { |a,e| a+e.size }.to_s
      [200, {"Content-Type" => "text/html", "Content-Length" => length}, content]
    }

    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

      res = Response.new
      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>"
      res.finish
    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

249 entries across 222 versions & 47 rubygems

Version Path
candlepin-api-0.4.0 bundle/ruby/1.9.1/gems/rack-1.3.5/lib/rack/lobster.rb
classiccms-0.7.2 vendor/bundle/gems/rack-1.4.1/lib/rack/lobster.rb
classiccms-0.7.1 vendor/bundle/gems/rack-1.4.1/lib/rack/lobster.rb
swipe-rails-0.0.5 vendor/bundle/gems/rack-1.4.5/lib/rack/lobster.rb
active_mailer-0.0.9 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/lobster.rb
active_mailer-0.0.8 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/lobster.rb
active_mailer-0.0.7 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/lobster.rb
active_mailer-0.0.6 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/lobster.rb
classiccms-0.7.0 vendor/bundle/gems/rack-1.4.1/lib/rack/lobster.rb
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/rack-1.4.5/lib/rack/lobster.rb
font-awesome-rails-3.1.1.2 vendor/ruby/2.0.0/gems/rack-1.4.5/lib/rack/lobster.rb
font-awesome-rails-3.1.1.1 vendor/ruby/2.0.0/gems/rack-1.4.5/lib/rack/lobster.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/rack-1.4.5/lib/rack/lobster.rb
challah-1.0.0.beta3 vendor/bundle/gems/rack-1.4.5/lib/rack/lobster.rb
fc-webicons-0.0.4 vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/lobster.rb
challah-1.0.0.beta2 vendor/bundle/gems/rack-1.4.5/lib/rack/lobster.rb
challah-1.0.0.beta vendor/bundle/gems/rack-1.4.3/lib/rack/lobster.rb
challah-1.0.0.beta vendor/bundle/gems/rack-1.4.5/lib/rack/lobster.rb
fc-webicons-0.0.3 vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/lobster.rb
fc-webicons-0.0.2 vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/lobster.rb