Class: Utopia::HTTP::Status
- Inherits:
-
Object
- Object
- Utopia::HTTP::Status
- Defined in:
- lib/utopia/http.rb
Overview
A small HTTP status wrapper that verifies the status code within a given range.
Instance Method Summary collapse
-
#initialize(code, valid_range = 100...600) ⇒ Status
constructor
Initialize a validated HTTP status.
-
#to_i ⇒ Object
Convert this value to an integer.
-
#to_s ⇒ Object
Convert this object to a string.
Constructor Details
#initialize(code, valid_range = 100...600) ⇒ Status
Initialize a validated HTTP status.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/utopia/http.rb', line 46 def initialize(code, valid_range = 100...600) if code.is_a? Symbol code = STATUS_CODES[code] end unless valid_range.include? code raise ArgumentError.new("Status must be in range #{valid_range}, was given #{code}!") end @code = code end |
Instance Method Details
#to_i ⇒ Object
Convert this value to an integer.
60 61 62 |
# File 'lib/utopia/http.rb', line 60 def to_i @code end |
#to_s ⇒ Object
Convert this object to a string.
66 67 68 |
# File 'lib/utopia/http.rb', line 66 def to_s return Protocol::HTTP::Status.description(@code) || @code.to_s end |