Permalink
Browse files

Extract ActionDispatch::Request#deep_munge

ActionDispatch::Request#deep_munge was introduced as a private method,
but was turned into a public one for the use of
ActionDispatch::ParamsParser.

I have extracted it into ActionDispatch::Request::Utils, so it does not
get mixed up with the Request public methods.
  • Loading branch information...
1 parent c2f3eff commit 5438f6866efa679331e5c998ecbc5948e80cd503 @gsamokovarov gsamokovarov committed May 30, 2013
@@ -22,6 +22,7 @@ class Request < Rack::Request
include ActionDispatch::Http::URL
autoload :Session, 'action_dispatch/request/session'
+ autoload :Utils, 'action_dispatch/request/utils'
LOCALHOST = Regexp.union [/^127\.0\.0\.\d{1,3}$/, /^::1$/, /^0:0:0:0:0:0:0:1(%.*)?$/]
@@ -299,26 +300,10 @@ def local?
LOCALHOST =~ remote_addr && LOCALHOST =~ remote_ip
end
- # Remove nils from the params hash
- def deep_munge(hash)
- hash.each do |k, v|
- case v
- when Array
- v.grep(Hash) { |x| deep_munge(x) }
- v.compact!
- hash[k] = nil if v.empty?
- when Hash
- deep_munge(v)
- end
- end
-
- hash
- end
-
protected
def parse_query(qs)
- deep_munge(super)
+ Utils.deep_munge(super)
end
private
@@ -43,7 +43,7 @@ def parse_formatted_parameters(env)
when :json
data = ActiveSupport::JSON.decode(request.body)
data = {:_json => data} unless data.is_a?(Hash)
- request.deep_munge(data).with_indifferent_access
+ Request::Utils.deep_munge(data).with_indifferent_access
else
false
end
@@ -0,0 +1,24 @@
+module ActionDispatch
+ class Request < Rack::Request
+ class Utils # :nodoc:
+ class << self
+ # Remove nils from the params hash
+ def deep_munge(hash)
+ hash.each do |k, v|
+ case v
+ when Array
+ v.grep(Hash) { |x| deep_munge(x) }
+ v.compact!
+ hash[k] = nil if v.empty?
+ when Hash
+ deep_munge(v)
+ end
+ end
+
+ hash
+ end
+ end
+ end
+ end
+end
+

3 comments on commit 5438f68

Owner

guilleiguaran replied Jun 2, 2013

👍

Owner

dhh replied Nov 3, 2013

This breaks actionpack-xml_parser and anyone else who might have depended on this as part of the public API. I don't see the point of this? What was gained by extracting it into a one-method class and then calling it anyway from the same place?

Owner

dhh replied Nov 3, 2013

I guess you are calling it from two separate places. I'll add a deprecated accessor back to request, but leave the extraction.

Please sign in to comment.