I’m sure this is not the right way to do it, but with some hacking I managed to make it “work”.
My branch is here
# My class
def my_keys
@rename_keys
end
define! do
map_array do
rename_keys(&:my_keys)
end
end
# lib/dry/transformer/hash.rb
def self.rename_keys(source_hash, mapping)
Hash[source_hash].tap do |hash|
# mapping.each { |k, v| hash[v] = hash.delete(k) if hash.key?(k) }
mapping.fn.call.each { |k, v| hash[v] = hash.delete(k) if hash.key?(k) }
end
end
Yep, its a very ugly hack that will probably break. Will keep investigating the proper way of doing this later today.