Exception: Rackful::HTTPStatus Abstract

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/rackful/httpstatus.rb

Overview

This class is abstract.

Exception which represents an HTTP Status response.

Direct Known Subclasses

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

Defined Under Namespace

Classes: Resource

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

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

Returns a new instance of HTTPStatus

Parameters:

  • status (Symbol, Integer)

    e.g. 404 or :not_found

  • message (String) (defaults to: nil)

    XHTML

  • info ({ Symbol => Object, String => String }) (defaults to: {})
    • Objects indexed by Symbols are returned in the response body.

    • Strings indexed by Strings are returned as response headers.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/rackful/httpstatus.rb', line 61

def initialize status, message = nil, info = {}
  @status = Rack::Utils.status_code status
  raise "Wrong status: #{status}" if 0 === @status
  message ||= ''
  @headers = {}
  @to_rackful = {}
  info.each do
    |k, v|
    if k.kind_of? Symbol
      @to_rackful[k] = v
    else
      @headers[k] = v.to_s
    end
  end
  @to_rackful = nil if @to_rackful.empty?
  if message
    message = message.to_s
    begin
      Nokogiri.XML(
        '<?xml version="1.0" encoding="UTF-8" ?>' +
        "<div>#{message}</div>"
      ) do |config| config.strict.nonet end
    rescue
      message = Rack::Utils.escape_html(message)
    end
  end
  super message
end

Instance Attribute Details

- (void) headers (readonly)

Returns the value of attribute headers



51
52
53
# File 'lib/rackful/httpstatus.rb', line 51

def headers
  @headers
end

- (void) status (readonly)

Returns the value of attribute status



51
52
53
# File 'lib/rackful/httpstatus.rb', line 51

def status
  @status
end

- (void) to_rackful (readonly)

Returns the value of attribute to_rackful



51
52
53
# File 'lib/rackful/httpstatus.rb', line 51

def to_rackful
  @to_rackful
end

Instance Method Details

- (void) serializer(request)



90
91
92
# File 'lib/rackful/httpstatus.rb', line 90

def serializer request
  Resource.new( request.url, self ).serializer( request )
end

- (void) title



94
95
96
# File 'lib/rackful/httpstatus.rb', line 94

def title
  "#{status} #{Rack::Utils::HTTP_STATUS_CODES[status]}"
end