Class: Httpstatus::Status
- Inherits:
-
Object
- Object
- Httpstatus::Status
- Defined in:
- lib/httpstatus/status.rb
Constant Summary collapse
- DEFAULT =
:internal_server_error
Instance Method Summary collapse
- #code ⇒ Object
- #default! ⇒ Object
- #default? ⇒ Boolean
- #error? ⇒ Boolean
-
#initialize(key = nil) ⇒ Status
constructor
A new instance of Status.
- #key ⇒ Object
- #key=(v) ⇒ Object
- #message ⇒ Object
- #title ⇒ Object
- #to_hash(*options) ⇒ Object (also: #to_h, #as_json)
- #to_json(*options) ⇒ Object
- #to_s ⇒ Object
- #to_xml(*options) ⇒ Object
- #to_yaml(*options) ⇒ Object
Constructor Details
#initialize(key = nil) ⇒ Status
Returns a new instance of Status.
5 6 7 |
# File 'lib/httpstatus/status.rb', line 5 def initialize key = nil self.key = key end |
Instance Method Details
#code ⇒ Object
18 19 20 |
# File 'lib/httpstatus/status.rb', line 18 def code i18n :code end |
#default! ⇒ Object
34 35 36 |
# File 'lib/httpstatus/status.rb', line 34 def default! @key = nil end |
#default? ⇒ Boolean
38 39 40 |
# File 'lib/httpstatus/status.rb', line 38 def default? status.key == DEFAULT end |
#error? ⇒ Boolean
30 31 32 |
# File 'lib/httpstatus/status.rb', line 30 def error? (400..599) === code end |
#key ⇒ Object
9 10 11 |
# File 'lib/httpstatus/status.rb', line 9 def key @key || DEFAULT end |
#key=(v) ⇒ Object
13 14 15 16 |
# File 'lib/httpstatus/status.rb', line 13 def key= v @key = v.is_a?(Symbol) ? v : (v.is_a?(String) ? v.to_sym : nil) default! unless valid? end |
#message ⇒ Object
26 27 28 |
# File 'lib/httpstatus/status.rb', line 26 def i18n :message end |
#title ⇒ Object
22 23 24 |
# File 'lib/httpstatus/status.rb', line 22 def title i18n :title end |
#to_hash(*options) ⇒ Object Also known as: to_h, as_json
42 43 44 |
# File 'lib/httpstatus/status.rb', line 42 def to_hash * { status: code, title: title, message: } end |
#to_json(*options) ⇒ Object
52 53 54 |
# File 'lib/httpstatus/status.rb', line 52 def to_json(*) to_h.to_json(*).html_safe end |
#to_s ⇒ Object
48 49 50 |
# File 'lib/httpstatus/status.rb', line 48 def to_s "#{code} #{title}\n#{}" end |
#to_xml(*options) ⇒ Object
60 61 62 |
# File 'lib/httpstatus/status.rb', line 60 def to_xml(*) to_h.to_xml(*).html_safe end |
#to_yaml(*options) ⇒ Object
56 57 58 |
# File 'lib/httpstatus/status.rb', line 56 def to_yaml(*) to_h.to_yaml(*).html_safe end |