Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Transproc::Transformer (class level transproc DSL) #73

Merged
merged 1 commit into from Aug 16, 2016

Conversation

Projects
None yet
3 participants
@AMHOL
Copy link
Collaborator

AMHOL commented Aug 15, 2016

require 'anima'
require 'transproc/all'

class User
  include Anima.new(:name, :address)
end

class Address
  include Anima.new(:city, :street, :zipcode)
end

class UsersMapper < Transproc::Transformer
  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


UsersMapper.new.call(
  [
    { 'user_name' => 'Jane',
      'city' => 'NYC',
      'street' => 'Street 1',
      'zipcode' => '123'
    }
  ]
)
# => [
#   #<User
#     name="Jane"
#     address=#<Address city="NYC" street="Street 1" zipcode="123">>
# ]

@AMHOL AMHOL force-pushed the feature/transformer branch from c6c4865 to b2299d8 Aug 15, 2016

@AMHOL AMHOL force-pushed the feature/transformer branch from b2299d8 to 8fe06d6 Aug 16, 2016

@solnic

This comment has been minimized.

Copy link
Owner

solnic commented Aug 16, 2016

This is awesome. I am so merging this in.

@solnic solnic merged commit ffe27d1 into master Aug 16, 2016

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@solnic solnic deleted the feature/transformer branch Aug 16, 2016

@AMHOL

This comment has been minimized.

Copy link
Collaborator Author

AMHOL commented Aug 16, 2016

🎉 nice one @solnic

@solnic

This comment has been minimized.

Copy link
Owner

solnic commented Aug 16, 2016

I just clicked on a button

On 16 August 2016 at 17:59:35, Andy Holland (notifications@github.com)
wrote:

🎉 nice one @solnic https://github.com/solnic


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#73 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAAEKkiN0-JKLnELkQb8XVjIg__kDPAlks5qgd5ngaJpZM4Jkl4G
.

@timriley

This comment has been minimized.

Copy link

timriley commented on lib/transproc/transformer.rb in 8fe06d6 Aug 23, 2016

Is this example in the docs missing a < Transproc::Transformer superclass, @AMHOL?

This comment has been minimized.

Copy link
Collaborator Author

AMHOL replied Aug 23, 2016

Indeed it is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.