imanel / output.txt secret
Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Test for deep_munge pull requests

View output.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
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"]}
View output.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
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
View output.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
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
View output.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
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
View output.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#!/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.