Last active
January 15, 2017 18:22
-
-
Save Kukunin/564d7d1b33f5538b5c3b1968a7731449 to your computer and use it in GitHub Desktop.
Transproc Transformer as ROM Mapper
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
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