class Rack::Quote
Constants
- HEADERS
attr_reader :app, :env, :options
Public Class Methods
new(app=nil, options={})
click to toggle source
# File lib/rack/ricky_quote.rb, line 6 def initialize(app=nil, options={}) @app = app @phrases = QuoteImporter.new end
Public Instance Methods
call(env)
click to toggle source
# File lib/rack/ricky_quote.rb, line 11 def call(env) if env['PATH_INFO'] == '/quote' quote = @phrases.random else quote = "" end if @app status, headers, response = @app.call(env) else status, headers, response = 200, {"Content-Type" => "text/plain"}, [] end response_body = "" response.each { |res| response_body += res } response_body += quote headers["Content-Length"] = response_body.length.to_s [status, headers, [response_body]] end