Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove extra constants from status reasons #332

Merged
merged 1 commit into from
Apr 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/http/response/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,31 @@ def to_s
# Check if status code is informational (1XX)
# @return [Boolean]
def informational?
INFORMATIONAL.keys.include?(code)
100 <= code && code < 200
end

# Check if status code is successful (2XX)
# @return [Boolean]
def success?
SUCCESSFUL.keys.include?(code)
200 <= code && code < 300
end

# Check if status code is redirection (3XX)
# @return [Boolean]
def redirect?
REDIRECTION.keys.include?(code)
300 <= code && code < 400
end

# Check if status code is client error (4XX)
# @return [Boolean]
def client_error?
CLIENT_ERROR.keys.include?(code)
400 <= code && code < 500
end

# Check if status code is server error (5XX)
# @return [Boolean]
def server_error?
SERVER_ERROR.keys.include?(code)
500 <= code && code < 600
end

# Symbolized {#reason}
Expand Down
30 changes: 5 additions & 25 deletions lib/http/response/status/reasons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ class Status < ::Delegator
# REASONS[414] # => "Request-URI Too Long"
#
# @return [Hash<Fixnum => String>]
INFORMATIONAL = {
REASONS = {
100 => "Continue",
101 => "Switching Protocols",
102 => "Processing"
}.each { |_, v| v.freeze }.freeze

SUCCESSFUL = {
102 => "Processing",
200 => "OK",
201 => "Created",
202 => "Accepted",
Expand All @@ -29,21 +26,15 @@ class Status < ::Delegator
206 => "Partial Content",
207 => "Multi-Status",
208 => "Already Reported",
226 => "IM Used"
}.each { |_, v| v.freeze }.freeze

REDIRECTION = {
226 => "IM Used",
300 => "Multiple Choices",
301 => "Moved Permanently",
302 => "Found",
303 => "See Other",
304 => "Not Modified",
305 => "Use Proxy",
307 => "Temporary Redirect",
308 => "Permanent Redirect"
}.each { |_, v| v.freeze }.freeze

CLIENT_ERROR = {
308 => "Permanent Redirect",
400 => "Bad Request",
401 => "Unauthorized",
402 => "Payment Required",
Expand All @@ -70,10 +61,7 @@ class Status < ::Delegator
428 => "Precondition Required",
429 => "Too Many Requests",
431 => "Request Header Fields Too Large",
451 => "Unavailable For Legal Reasons"
}.each { |_, v| v.freeze }.freeze

SERVER_ERROR = {
451 => "Unavailable For Legal Reasons",
500 => "Internal Server Error",
501 => "Not Implemented",
502 => "Bad Gateway",
Expand All @@ -86,14 +74,6 @@ class Status < ::Delegator
510 => "Not Extended",
511 => "Network Authentication Required"
}.each { |_, v| v.freeze }.freeze

REASONS = [
INFORMATIONAL,
SUCCESSFUL,
REDIRECTION,
CLIENT_ERROR,
SERVER_ERROR
].inject(&:merge).each { |_, v| v.freeze }.freeze
end
end
end