Sha256: 8157921839ef51961ca14cbb584157307272a7ccbed867b1e77adcdf025176af

Contents?: true

Size: 799 Bytes

Versions: 1

Compression:

Stored size: 799 Bytes

Contents

---
title: Transformation objects
name: dry-transformer
layout: gem-single
---

You can define transformation classes using the DSL which converts every method call to its corresponding transformation, and composes these transformations into a transformation pipeline. Here's a simple example where the default registry is used:

```ruby
class MyMapper < Dry::Transformer[Dry::Transformer::Registry]
  define! do
    map_array do
      symbolize_keys
      rename_keys user_name: :name
      nest :address, [:city, :street, :zipcode]
    end
  end
end

mapper = MyMapper.new

mapper.(
  [
    { 'user_name' => 'Jane',
      'city' => 'NYC',
      'street' => 'Street 1',
      'zipcode' => '123'
    }
  ]
)
# => [{:name=>"Jane", :address=>{:city=>"NYC", :street=>"Street 1", :zipcode=>"123"}}]
```

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-transformer-0.1.0 docsite/source/transformation-objects.html.md