Skip to content

Instantly share code, notes, and snippets.

@solnic
Last active February 4, 2017 10:16
Show Gist options
  • Save solnic/d9ef5c8db87d20da4cd6 to your computer and use it in GitHub Desktop.
Save solnic/d9ef5c8db87d20da4cd6 to your computer and use it in GitHub Desktop.
Custom coercer in ROM using transproc
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