Skip to content

Instantly share code, notes, and snippets.

@solnic
Last active February 4, 2017 10:16
Show Gist options
  • Select an option

  • Save solnic/d9ef5c8db87d20da4cd6 to your computer and use it in GitHub Desktop.

Select an option

Save solnic/d9ef5c8db87d20da4cd6 to your computer and use it in GitHub Desktop.

Revisions

  1. solnic revised this gist Mar 25, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rom_custom_coercion_mapper.rb
    Original file line number Diff line number Diff line change
    @@ -11,4 +11,4 @@ class GothamCityMapper < ROM::Mapper
    m = GothamCityMapper.build

    puts m.call [{ superhero: 'Bruce Wayne' }]
    # => {:superhero=>#<struct Batman secret_name="Bruce Wayne">}
    # => [{:superhero=>#<struct Batman secret_name="Bruce Wayne">}]
  2. solnic created this gist Mar 25, 2015.
    14 changes: 14 additions & 0 deletions rom_custom_coercion_mapper.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    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">}