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
# 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:
TRANSPROC_VERSION=1.0.2 rb test.rb # this works
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?
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