Skip to content

Instantly share code, notes, and snippets.

@Kukunin
Last active January 15, 2017 18:22
Show Gist options
  • Save Kukunin/564d7d1b33f5538b5c3b1968a7731449 to your computer and use it in GitHub Desktop.
Save Kukunin/564d7d1b33f5538b5c3b1968a7731449 to your computer and use it in GitHub Desktop.
Transproc Transformer as ROM Mapper
module RomInterface
def self.extended(klass)
klass.extend ROM::ClassMacros
klass.defines :relation, :register_as
end
def base_relation
relation
end
def build
new
end
end
class CustomersMapper < Transproc::Transformer
extend RomInterface
relation :customers
register_as :tuple
map_array do
symbolize_keys
rename_keys user_name: :name
nest :address, %i(city street zipcode)
map_value :address do
constructor_inject Address
end
constructor_inject User
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment