Exception: Maveric::Response

Inherits:
Exception
  • Object
show all
Defined in:
lib/maveric.rb

Overview

Response is an Exception class that can be raised from within a call to maveric#response, with 401, 403, and 404 errors provided.

raise Maveric::Response, 404 will look up 404 via Response#[] and if a value is found, it is utilized to set the status, headers, and body.

raise Maveric::Response, 'Bad stuff' will generate a plain-text 500 response with the message as the body of the response.

Additional or replacement responses should be set via Response#[]= and should be valid rack responses.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(err) ⇒ Response

Returns a new instance of Response.



255
256
257
258
259
260
261
# File 'lib/maveric.rb', line 255

def initialize err
  resp = Response[err] || [ DEFAULT[0],
    { 'Content-Type' => DEFAULT[1], 'Content-Length' => err.length.to_s },
    err]
  @status, @headers, @body = resp
  super @body
end

Class Method Details

.[](e) ⇒ Object



253
# File 'lib/maveric.rb', line 253

def self.[] e; @r[e]; end

.[]=(e, v) ⇒ Object



254
# File 'lib/maveric.rb', line 254

def self.[]= e, v; @r[e]=v; end

Instance Method Details

#eachObject



262
# File 'lib/maveric.rb', line 262

def each; @body.each{|line| yield line }; end

#to_aObject Also known as: finish

to_splat in 1.9



263
# File 'lib/maveric.rb', line 263

def to_a; [@status, @headers, self]; end