Exception: Rackful::HTTPStatus Abstract

Inherits:
RuntimeError
  • Object
show all
Includes:
Resource
Defined in:
gems/rackful-0.1.1/lib/rackful_http_status.rb,
gems/rackful-0.1.1.orig/lib/rackful_http_status.rb

Overview

This class is abstract.

Exception which represents an HTTP Status response.

Since:

Direct Known Subclasses

HTTP201Created, HTTP202Accepted, HTTP301MovedPermanently, HTTP303SeeOther, HTTP304NotModified, HTTP307TemporaryRedirect, HTTP405MethodNotAllowed, HTTP406NotAcceptable, HTTP412PreconditionFailed, HTTP415UnsupportedMediaType, HTTPSimpleStatus

Defined Under Namespace

Classes: XHTML

Instance Attribute Summary (collapse)

Attributes included from Resource

#get_etag, #get_last_modified, #path

Instance Method Summary (collapse)

Methods included from Resource

#default_headers, #destroy, #do_METHOD, #empty?, #http_DELETE, #http_GET, #http_HEAD, #http_OPTIONS, #http_PUT, #http_method, #http_methods, included, #requested?, #serializer, #title, #to_struct

Constructor Details

- (HTTPStatus) initialize(status, message = nil, info = {})

A new instance of HTTPStatus

Parameters:

  • message (String) (defaults to: nil)

    XHTML

  • status (Symbol, Integer)

    e.g. `404` or `:not_found`

  • headers (Hash)

    HTTP response headers

Since:

  • 0.1.0



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'gems/rackful-0.1.1/lib/rackful_http_status.rb', line 28

def initialize status, message = nil, info = {}
  self.path = Request.current.path
  @status = status_code status
  raise "Wrong status: #{status}" if 0 == @status
  message ||= ''
  @headers = {}
  @to_rackful = {}
  info.each do
    |k, v|
    if k.kind_of? Symbol then @to_rackful[k] = v
    else @headers[k] = v end
  end
  @to_rackful = nil if @to_rackful.empty?
  begin
    REXML::Document.new \
      '<?xml version="1.0" encoding="UTF-8" ?>' +
      "<div>#{message}</div>"
  rescue
    message = Rack::Utils.escape_html(message)
  end
  super message
  if 500 <= @status
    errors = Request.current.env['rack.errors']
    errors.puts self.inspect
    errors.puts "Headers: #{@headers.inspect}"
    errors.puts "Info: #{@to_rackful.inspect}"
  end
end

Instance Attribute Details

- (void) headers (readonly)

Since:

  • 0.1.0



20
21
22
# File 'gems/rackful-0.1.1/lib/rackful_http_status.rb', line 20

def headers
  @headers
end

- (void) status (readonly)

Since:

  • 0.1.0



20
21
22
# File 'gems/rackful-0.1.1/lib/rackful_http_status.rb', line 20

def status
  @status
end

- (void) to_rackful (readonly)

Since:

  • 0.1.0



20
21
22
# File 'gems/rackful-0.1.1/lib/rackful_http_status.rb', line 20

def to_rackful
  @to_rackful
end