Last active
August 29, 2015 14:27
-
-
Save luxflux/ab6d15a44385cd993e16 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rom-mapper' | |
require 'pp' | |
input = { | |
a: { | |
b: {}, | |
c: { | |
d: [ | |
{ | |
something: { | |
key: 'value', | |
}, | |
yay: 1 | |
}, | |
{}, | |
{} | |
] | |
} | |
} | |
} | |
class Preprocessor < ROM::Mapper | |
reject_keys true | |
step do | |
unwrap :a do | |
attribute :c | |
end | |
end | |
step do | |
unwrap :c do | |
attribute :items, from: :d | |
end | |
end | |
step do | |
ungroup :items do | |
attribute :something | |
end | |
end | |
step do | |
unwrap :something do | |
attribute :key | |
end | |
end | |
end | |
preprocessor = Preprocessor.build | |
pp preprocessor.call([input]).first |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby -W0 mapper2.rb | |
/opt/rubies/2.2.2/lib/ruby/gems/2.2.0/gems/transproc-0.3.2/lib/transproc/hash.rb:216:in `[]': Failed to call_function map_array with [[{:something=>{:key=>"value"}}, {:something=>nil}, {:something=>nil}]] - Failed to call_function map_value with [{:something=>nil}] - Failed to call_function accept_keys with [nil] - odd number of arguments for Hash (Transproc::MalformedInputError) | |
from /opt/rubies/2.2.2/lib/ruby/gems/2.2.0/gems/transproc-0.3.2/lib/transproc/hash.rb:216:in `accept_keys' | |
from /opt/rubies/2.2.2/lib/ruby/gems/2.2.0/gems/transproc-0.3.2/lib/transproc/function.rb:47:in `call' | |
from /opt/rubies/2.2.2/lib/ruby/gems/2.2.0/gems/transproc-0.3.2/lib/transproc/function.rb:47:in `call' | |
from /opt/rubies/2.2.2/lib/ruby/gems/2.2.0/gems/transproc-0.3.2/lib/transproc/hash.rb:240:in `map_value' | |
from /opt/rubies/2.2.2/lib/ruby/gems/2.2.0/gems/transproc-0.3.2/lib/transproc/function.rb:47:in `call' | |
from /opt/rubies/2.2.2/lib/ruby/gems/2.2.0/gems/transproc-0.3.2/lib/transproc/function.rb:47:in `call' | |
from /opt/rubies/2.2.2/lib/ruby/gems/2.2.0/gems/transproc-0.3.2/lib/transproc/composite.rb:30:in `call' | |
from /opt/rubies/2.2.2/lib/ruby/gems/2.2.0/gems/transproc-0.3.2/lib/transproc/composite.rb:30:in `call' | |
from /opt/rubies/2.2.2/lib/ruby/gems/2.2.0/gems/transproc-0.3.2/lib/transproc/array.rb:50:in `block in map_array!' | |
from /opt/rubies/2.2.2/lib/ruby/gems/2.2.0/gems/transproc-0.3.2/lib/transproc/array.rb:50:in `map!' | |
from /opt/rubies/2.2.2/lib/ruby/gems/2.2.0/gems/transproc-0.3.2/lib/transproc/array.rb:50:in `map_array!' | |
from /opt/rubies/2.2.2/lib/ruby/gems/2.2.0/gems/transproc-0.3.2/lib/transproc/array.rb:41:in `map_array' | |
from /opt/rubies/2.2.2/lib/ruby/gems/2.2.0/gems/transproc-0.3.2/lib/transproc/function.rb:47:in `call' | |
from /opt/rubies/2.2.2/lib/ruby/gems/2.2.0/gems/transproc-0.3.2/lib/transproc/function.rb:47:in `call' | |
from /opt/rubies/2.2.2/lib/ruby/gems/2.2.0/gems/rom-mapper-0.2.0/lib/rom/mapper.rb:95:in `block in call' | |
from /opt/rubies/2.2.2/lib/ruby/gems/2.2.0/gems/rom-mapper-0.2.0/lib/rom/mapper.rb:95:in `each' | |
from /opt/rubies/2.2.2/lib/ruby/gems/2.2.0/gems/rom-mapper-0.2.0/lib/rom/mapper.rb:95:in `reduce' | |
from /opt/rubies/2.2.2/lib/ruby/gems/2.2.0/gems/rom-mapper-0.2.0/lib/rom/mapper.rb:95:in `call' | |
from rom-mapper-testing.rb:53:in `<main>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment