Created
December 9, 2015 14:11
-
-
Save gotar/dddd8d3977738f9018ee to your computer and use it in GitHub Desktop.
mapper problem
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' | |
class MyMapper1 < ROM::Mapper | |
reject_keys true | |
attribute :foo, from: [:bar, :baz] do |bar, baz| | |
[bar, baz] | |
end | |
end | |
class MyMapper2 < ROM::Mapper | |
reject_keys true | |
attribute :foo, from: ['bar', 'baz'] do |bar, baz| | |
[bar, baz] | |
end | |
end | |
class MyMapper3 < ROM::Mapper | |
reject_keys true | |
symbolize_keys true | |
attribute :foo, from: [:bar, :baz] do |bar, baz| | |
[bar, baz] | |
end | |
end | |
class MyMapper4 < ROM::Mapper | |
reject_keys true | |
symbolize_keys true | |
attribute :foo, from: ['bar', 'baz'] do |bar, baz| | |
[bar, baz] | |
end | |
end | |
params = [{ | |
'bar' => 'bar', | |
'baz' => 'baz' | |
}] | |
MyMapper2.build.call(params) # => [{:foo=>[nil, nil]}] | |
MyMapper2.build.call(params) # => [{:foo=>["bar", "baz"]}] | |
MyMapper3.build.call(params) # => [{:foo=>[nil, nil]}] | |
MyMapper4.build.call(params) # => [{:foo=>[nil, nil]}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment