Class: Utopia::HTTP::Status

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(code, valid_range = 100...600) ⇒ Status

Returns a new instance of Status.



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/utopia/http.rb', line 97

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

#each {|to_s| ... } ⇒ Object

Allow to be used for rack body:

Yields:



118
119
120
# File 'lib/utopia/http.rb', line 118

def each
	yield to_s
end

#to_iObject



109
110
111
# File 'lib/utopia/http.rb', line 109

def to_i
	@code
end

#to_sObject



113
114
115
# File 'lib/utopia/http.rb', line 113

def to_s
	STATUS_DESCRIPTIONS[@code] || @code.to_s
end