Permalink
Browse files

Reduce usage of interpret_status. It should also return a integer

not a string.
  • Loading branch information...
1 parent c517a4f commit 1b82590c36bb1404f7b7a9aa9cf196253685d73f @josh josh committed Dec 11, 2009
View
16 actionpack/lib/action_controller/base.rb
@@ -19,7 +19,6 @@ class Base < Metal
# Legacy modules
include SessionManagement
- include ActionDispatch::StatusCodes
include ActionController::Caching
include ActionController::MimeResponds
@@ -91,7 +90,7 @@ def _normalize_options(action = nil, options = {}, &blk)
end
if options[:status]
- options[:status] = interpret_status(options[:status]).to_i
+ options[:status] = _interpret_status(options[:status])
end
options[:update] = blk if block_given?
@@ -140,9 +139,9 @@ def redirect_to(options = {}, response_status = {}) #:doc:
raise ActionControllerError.new("Cannot redirect to nil!") if options.nil?
status = if options.is_a?(Hash) && options.key?(:status)
- interpret_status(options.delete(:status))
+ _interpret_status(options.delete(:status))
elsif response_status.key?(:status)
- interpret_status(response_status[:status])
+ _interpret_status(response_status[:status])
else
302
end
@@ -164,5 +163,14 @@ def redirect_to(options = {}, response_status = {}) #:doc:
super(url, status)
end
+
+ private
+ def _interpret_status(status)
+ if status.is_a?(Symbol)
+ (ActionDispatch::StatusCodes::SYMBOL_TO_STATUS_CODE[status] || 500)
+ else
+ status.to_i
+ end
+ end
end
end
View
17 actionpack/lib/action_dispatch/http/status_codes.rb
@@ -21,22 +21,5 @@ module StatusCodes #:nodoc:
hash[ActiveSupport::Inflector.underscore(message.gsub(/ /, "")).to_sym] = code
hash
}.freeze
-
- private
- # Given a status parameter, determine whether it needs to be converted
- # to a string. If it is a fixnum, use the STATUS_CODES hash to lookup
- # the default message. If it is a symbol, use the SYMBOL_TO_STATUS_CODE
- # hash to convert it.
- def interpret_status(status)
- case status
- when Fixnum then
- "#{status} #{STATUS_CODES[status]}".strip
- when Symbol then
- interpret_status(SYMBOL_TO_STATUS_CODE[status] ||
- "500 Unknown Status #{status.inspect}")
- else
- status.to_s
- end
- end
end
end
View
4 actionpack/lib/action_dispatch/middleware/show_exceptions.rb
@@ -2,8 +2,6 @@
module ActionDispatch
class ShowExceptions
- include StatusCodes
-
LOCALHOST = '127.0.0.1'.freeze
RESCUES_TEMPLATE_PATH = File.join(File.dirname(__FILE__), 'templates')
@@ -104,7 +102,7 @@ def local_request?(request)
end
def status_code(exception)
- interpret_status(@@rescue_responses[exception.class.name]).to_i
+ ActionDispatch::StatusCodes::SYMBOL_TO_STATUS_CODE[@@rescue_responses[exception.class.name]]
end
def render(status, body)

0 comments on commit 1b82590

Please sign in to comment.