2010-01-16 07:17:03 -05:00
|
|
|
require 'active_support/core_ext/hash/keys'
|
2010-04-21 00:58:58 -04:00
|
|
|
require 'active_support/core_ext/hash/indifferent_access'
|
2010-01-16 07:17:03 -05:00
|
|
|
|
|
|
|
module ActionDispatch
|
|
|
|
module Http
|
|
|
|
module Parameters
|
2014-05-27 17:46:04 -04:00
|
|
|
PARAMETERS_KEY = 'action_dispatch.request.path_parameters'
|
|
|
|
|
2010-01-16 07:17:03 -05:00
|
|
|
# Returns both GET and POST \parameters in a single hash.
|
|
|
|
def parameters
|
2010-06-28 00:12:10 -04:00
|
|
|
@env["action_dispatch.request.parameters"] ||= begin
|
2012-12-10 08:59:06 -05:00
|
|
|
params = begin
|
|
|
|
request_parameters.merge(query_parameters)
|
|
|
|
rescue EOFError
|
|
|
|
query_parameters.dup
|
|
|
|
end
|
2010-06-28 00:12:10 -04:00
|
|
|
params.merge!(path_parameters)
|
|
|
|
end
|
2010-01-16 07:17:03 -05:00
|
|
|
end
|
|
|
|
alias :params :parameters
|
|
|
|
|
|
|
|
def path_parameters=(parameters) #:nodoc:
|
2014-05-22 10:49:29 -04:00
|
|
|
@env.delete('action_dispatch.request.parameters')
|
2014-05-27 17:46:04 -04:00
|
|
|
@env[PARAMETERS_KEY] = parameters
|
2010-01-16 07:17:03 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# Returns a hash with the \parameters used to form the \path of the request.
|
|
|
|
# Returned hash keys are strings:
|
|
|
|
#
|
|
|
|
# {'action' => 'my_action', 'controller' => 'my_controller'}
|
|
|
|
def path_parameters
|
2014-05-27 17:46:04 -04:00
|
|
|
@env[PARAMETERS_KEY] ||= {}
|
2010-01-16 07:17:03 -05:00
|
|
|
end
|
|
|
|
|
2010-01-20 10:55:33 -05:00
|
|
|
private
|
2010-06-28 00:12:10 -04:00
|
|
|
|
2014-04-14 06:09:06 -04:00
|
|
|
# Convert nested Hash to HashWithIndifferentAccess.
|
2012-03-26 23:54:24 -04:00
|
|
|
#
|
|
|
|
def normalize_encode_params(params)
|
2013-08-19 14:17:11 -04:00
|
|
|
case params
|
|
|
|
when Hash
|
|
|
|
if params.has_key?(:tempfile)
|
|
|
|
UploadedFile.new(params)
|
2013-06-04 06:34:43 -04:00
|
|
|
else
|
2013-08-19 14:23:03 -04:00
|
|
|
params.each_with_object({}) do |(key, val), new_hash|
|
2014-04-14 06:09:06 -04:00
|
|
|
new_hash[key] = if val.is_a?(Array)
|
2013-08-19 14:17:11 -04:00
|
|
|
val.map! { |el| normalize_encode_params(el) }
|
|
|
|
else
|
|
|
|
normalize_encode_params(val)
|
|
|
|
end
|
2013-08-19 14:23:03 -04:00
|
|
|
end.with_indifferent_access
|
2013-06-04 06:34:43 -04:00
|
|
|
end
|
2013-08-19 14:17:11 -04:00
|
|
|
else
|
|
|
|
params
|
2010-01-16 07:17:03 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-04-21 00:58:58 -04:00
|
|
|
end
|