I have tried today used dry-transformation
to transform payload which I receive from AWS SNS/SQS to shape which I need.
I have found that nest
method (HashTransformation) doesn’t work with hash value? I can only assume that nest
support only primitive datatype - Hash and Array aren’t supported. I am wondering why. Is there any reason for it?
example:
class MyMapper < Dry::Transformer::Pipe
import Dry::Transformer::HashTransformations
define! do
unwrap :payload
nest :order_fields, [:name, :description, :price]
end
end
MyMapper.new.call({
payload: {
name: "foo",
description: "bar",
price: {
value: "1.1",
currency: "EUR"
}
}
})
It raises exception:
function name +price+ is not valid (Dry::Transformer::Compiler::InvalidFunctionNameError)
but when I changed it a bit to:
class MyMapper < Dry::Transformer::Pipe
import Dry::Transformer::HashTransformations
define! do
unwrap :payload
nest :order_fields, [:name, :description]
nest :order_fields, [:price]
end
end
Then it works.