Hey,
I think of something like this:
module Dry
module Transformer
module HashTransformations
def self.map(source_hash, fn)
source_hash.map { |key, value| fn.call(key, value) }.to_h
end
end
end
end
to achieve following:
transformation = Dry::Transformer::Recursion
.t(:recursion, Dry::Transformer::Conditional
.t(:is, ::Hash, Dry::Transformer::HashTransformations
.t(:map, ->(key, value) { [:time_from, :time_until].include?(key) ? [key, Time.parse(value)] : [key, value] })))
transformation.call({
id: 1,
address: { street: "Schulstrasse", zip_code: "6555" },
from: "2023-02-09T09:03:06.144+00:00",
until: "2023-02-10T09:03:06.144+00:00",
})
# {
# id: 1,
# address: { street: "Schulstrasse", zip_code: "6555" },
# from: 2023-02-09 10:03:06.144899502 +0100,
# until: 2023-02-10 10:03:06.144899502 +0100,
# }
I had this use-case and could not find a solution with the built-in transformations
Thanks