class Httpstatus::Status

Constants

DEFAULT

Public Class Methods

new(key = nil) click to toggle source
# File lib/httpstatus/status.rb, line 5
def initialize key = nil
  self.key = key
end

Public Instance Methods

as_json(*options)
Alias for: to_hash
code() click to toggle source
# File lib/httpstatus/status.rb, line 18
def code
  i18n :code
end
default!() click to toggle source
# File lib/httpstatus/status.rb, line 34
def default!
  @key = nil
end
default?() click to toggle source
# File lib/httpstatus/status.rb, line 38
def default?
  status.key == DEFAULT
end
error?() click to toggle source
# File lib/httpstatus/status.rb, line 30
def error?
  (400..599) === code
end
key() click to toggle source
# File lib/httpstatus/status.rb, line 9
def key
  @key || DEFAULT
end
key=(v) click to toggle source
# 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() click to toggle source
# File lib/httpstatus/status.rb, line 26
def message
  i18n :message
end
title() click to toggle source
# File lib/httpstatus/status.rb, line 22
def title
  i18n :title
end
to_h(*options)
Alias for: to_hash
to_hash(*options) click to toggle source
# File lib/httpstatus/status.rb, line 42
def to_hash *options
  { status: code, title: title, message: message }
end
Also aliased as: to_h, as_json
to_json(*options) click to toggle source
# File lib/httpstatus/status.rb, line 52
def to_json(*options)
  to_h.to_json(*options).html_safe
end
to_s() click to toggle source
# File lib/httpstatus/status.rb, line 48
def to_s
  "#{code} #{title}\n#{message}"
end
to_xml(*options) click to toggle source
# File lib/httpstatus/status.rb, line 60
def to_xml(*options)
  to_h.to_xml(*options).html_safe
end
to_yaml(*options) click to toggle source
# File lib/httpstatus/status.rb, line 56
def to_yaml(*options)
  to_h.to_yaml(*options).html_safe
end

Protected Instance Methods

i18n(property) click to toggle source
# File lib/httpstatus/status.rb, line 70
def i18n(property)
  I18n.t "http_status.#{key}.#{property}"
end
valid?() click to toggle source
# File lib/httpstatus/status.rb, line 66
def valid?
  code.is_a?(Integer) && title.is_a?(String) && message.is_a?(String)
end