Last active
February 4, 2017 10:16
-
-
Save solnic/d9ef5c8db87d20da4cd6 to your computer and use it in GitHub Desktop.
Custom coercer in ROM using transproc
This file contains 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' | |
Batman = Struct.new(:secret_name) | |
Transproc.register(:to_batman, proc { |name| Batman.new(name) }) | |
class GothamCityMapper < ROM::Mapper | |
attribute :superhero, type: :batman | |
end | |
m = GothamCityMapper.build | |
puts m.call [{ superhero: 'Bruce Wayne' }] | |
# => [{:superhero=>#<struct Batman secret_name="Bruce Wayne">}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment