Skip to content

Instantly share code, notes, and snippets.

@gotar
Created December 9, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gotar/dddd8d3977738f9018ee to your computer and use it in GitHub Desktop.
Save gotar/dddd8d3977738f9018ee to your computer and use it in GitHub Desktop.
mapper problem
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