# Upgrading to Transproc 1.1.0, issue with class methods

**URL:** <https://discourse.rom-rb.org/t/upgrading-to-transproc-1-1-0-issue-with-class-methods/331>\
**Category:** Issues\
**Created:** [August 2, 2019, 5:31pm UTC](https://discourse.rom-rb.org/t/upgrading-to-transproc-1-1-0-issue-with-class-methods/331 "2019-08-02T17:31:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ianks](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/ianks/32/145_2.png) [@ianks](https://discourse.rom-rb.org/u/ianks)\
**Post date:** [August 2, 2019, 5:31pm UTC](https://discourse.rom-rb.org/t/upgrading-to-transproc-1-1-0-issue-with-class-methods/331/1 "2019-08-02T17:31:17Z")

</div>

Happy friday!

We are trying to upgrade to hanami 1.3.2, which in turn is making us upgrade Transproc to 1.1.0. We have some mappers which relied on Transformer class methods being available with on declaration, but now we are getting `undefined` method errors.

## Reproducible Code

```ruby
# test.rb

require 'bundler/inline'

gemfile do
  source "https://rubygems.org"

  gem "rom"

  # doesnt work on 1.1.0
  gem "transproc", ENV.fetch('TRANSPROC_VERSION')
end

require 'rom/transformer'

class ProductMapper < ROM::Transformer
  class << self
    def prepare(value)
      value.to_s.strip
    end
  end

  map_array do
    map_value :name, method(:prepare)
  end
end

puts ProductMapper.new.call([name: ' test '])

```

To illustrate the issue, run the following commands:

```auto
TRANSPROC_VERSION=1.0.2 rb test.rb # this works

```

```auto
TRANSPROC_VERSION=1.1.0 rb test.rb # this does not work

```

## Question

What is the best pattern for defining methods in a Transformer which can be used in declarations? i.e. how could I refactor the above code to work on 1.1.0?

Thank you for your hard work and time ❤

---

<div class="post-metadata">

**Author:** ![solnic](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/solnic/32/279_2.png) [@solnic](https://discourse.rom-rb.org/u/solnic)\
**Post date:** [August 6, 2019, 8:39am UTC](https://discourse.rom-rb.org/t/upgrading-to-transproc-1-1-0-issue-with-class-methods/331/2 "2019-08-06T08:39:50Z")

</div>

Hmm weird, looks like a regression. Anyhow, you can now use instance methods with shorter syntax:

```ruby
require 'rom/transformer'

class ProductMapper < ROM::Transformer
  map do
    map_value(:name, &:prepare)
  end

  def prepare(value)
    value.to_s.strip
  end
end

```

❗ Notice `map` instead of `map_array` ❗

---

<div class="post-metadata">

**Author:** ![ianks](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/ianks/32/145_2.png) [@ianks](https://discourse.rom-rb.org/u/ianks)\
**Post date:** [August 7, 2019, 3:40pm UTC](https://discourse.rom-rb.org/t/upgrading-to-transproc-1-1-0-issue-with-class-methods/331/3 "2019-08-07T15:40:47Z")

</div>

@solnic Using `map` does not seem to work for me. Getting this error:

```auto
Traceback (most recent call last):
	2: from tmp/test.rb:16:in `<main>'
	1: from tmp/test.rb:17:in `<class:ProductMapper>'
/home/ianks/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/transproc-1.1.0/lib/transproc/transformer/deprecated/class_interface.rb:53:in `method_missing': undefined method `map' for ProductMapper:Class (NoMethodError)

```

---

<div class="post-metadata">

**Author:** ![ianks](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/ianks/32/145_2.png) [@ianks](https://discourse.rom-rb.org/u/ianks)\
**Post date:** [August 7, 2019, 3:51pm UTC](https://discourse.rom-rb.org/t/upgrading-to-transproc-1-1-0-issue-with-class-methods/331/4 "2019-08-07T15:51:27Z")

</div>

> [@solnic](#):
>
> require ‘rom/transformer’ class ProductMapper \< ROM::Transformer map do map\_value(:name, &:prepare) end def prepare(value) value.to\_s.strip end end

Looks like this will work as well:

```ruby
require 'rom/transformer'

class ProductMapper < ROM::Transformer
  define! do
    map_array do
      map_value :name, &:prepare
    end
  end

  def prepare(value)
    value.to_s.strip
  end
end

```

---

<div class="post-metadata">

**Author:** ![solnic](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/solnic/32/279_2.png) [@solnic](https://discourse.rom-rb.org/u/solnic)\
**Post date:** [August 7, 2019, 5:01pm UTC](https://discourse.rom-rb.org/t/upgrading-to-transproc-1-1-0-issue-with-class-methods/331/5 "2019-08-07T17:01:17Z")

</div>

Ah sorry, forgot to mention this requires rom 5.1.0.

---

<div class="post-metadata">

**Author:** ![ianks](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/ianks/32/145_2.png) [@ianks](https://discourse.rom-rb.org/u/ianks)\
**Post date:** [August 21, 2019, 10:47am UTC](https://discourse.rom-rb.org/t/upgrading-to-transproc-1-1-0-issue-with-class-methods/331/6 "2019-08-21T10:47:47Z")

</div>

No problem. Issue has now been resolved, thank you!
