Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Test for deep_munge pull requests
Output for rails_master.rb
Input | Output
{:person=>nil} | {:person=>nil}
{:person=>[]} | {:person=>nil}
{:person=>[]} | {:person=>nil}
{:person=>[]} | {:person=>nil}
{:person=>["foo"]} | {:person=>["foo"]}
Output for pull_11044.rb
Input | Output
{:person=>nil} | {:person=>nil}
{:person=>[]} | {:person=>[]}
{:person=>[]} | {:person=>nil}
{:person=>[]} | {:person=>nil}
{:person=>["foo"]} | {:person=>["foo"]}
Output for pull_12251.rb
Input | Output
{:person=>nil} | {:person=>nil}
{:person=>[]} | {:person=>[]}
{:person=>[]} | {:person=>[]}
{:person=>[]} | {:person=>[]}
{:person=>["foo"]} | {:person=>["foo"]}
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) }
if v.empty?
hash[k] = []
else
v.compact!
hash[k] = nil if v.empty?
end
when Hash
deep_munge(v)
end
end
hash
end
end
end
end
end
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!
when Hash
deep_munge(v)
end
end
hash
end
end
end
end
end
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
#!/usr/bin/env ruby
# USAGE
# $ ruby tester.rb filename
require 'rack/request'
require "./#{ARGV.first}"
EXAMPLES = [
{ person: nil },
{ person: [] },
{ person: [nil] },
{ person: [nil, nil, nil] },
{ person: ["foo", nil] }
]
# puts ActionDispatch::Request::Utils.deep_munge(EXAMPLES.first).inspect
separator = " | "
column_size = 20
puts "Output for #{ARGV.first}"
puts "Input".ljust(column_size) + separator + "Output"
EXAMPLES.each do |input|
output = ActionDispatch::Request::Utils.deep_munge(input.dup)
puts input.inspect.ljust(column_size) + separator + output.inspect
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.