Class: Rack::Lobster

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/lobster.rb

Overview

Paste has a Pony, Rack has a Lobster!

Constant Summary collapse

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>"]
  ]
}

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rack/lobster.rb', line 32

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