Sha256: bf3399e8fad2a64627d3f27db84ae2de8a6e7f84df277ee2dc65245cf1015432

Contents?: true

Size: 1.97 KB

Versions: 55

Compression:

Stored size: 1.97 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 do |line|
          line.ljust(42).reverse.
            gsub('\\', 'TEMP').
            gsub('/', '\\').
            gsub('TEMP', '/').
            gsub('{','}').
            gsub('(',')')
        end.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/show_exceptions'
  Rack::Server.start(
    :app => Rack::ShowExceptions.new(Rack::Lint.new(Rack::Lobster.new)), :Port => 9292
  )
end

Version data entries

55 entries across 53 versions & 14 rubygems

Version Path
rack-2.0.9.4 lib/rack/lobster.rb
rack-2.0.9.3 lib/rack/lobster.rb
rack-2.0.9.2 lib/rack/lobster.rb
rack-2.0.9.1 lib/rack/lobster.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/rack-2.0.5/lib/rack/lobster.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rack-2.0.8/lib/rack/lobster.rb
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/lobster.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/rack-2.0.6/lib/rack/lobster.rb
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/lib/rack/lobster.rb
rack-2.0.9 lib/rack/lobster.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rack-2.0.8/lib/rack/lobster.rb
rack-2.0.8 lib/rack/lobster.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rack-2.0.7/lib/rack/lobster.rb
tdiary-5.1.0 vendor/bundle/gems/rack-2.0.7/lib/rack/lobster.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rack-2.0.7/lib/rack/lobster.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/lib/rack/lobster.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/lib/rack/lobster.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/rack-2.0.7/lib/rack/lobster.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/rack-2.0.7/lib/rack/lobster.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/rack-2.0.7/lib/rack/lobster.rb