Extract block to helper function

This commit is contained in:
Maciej Szlosarczyk 2018-04-24 13:19:11 +03:00
parent b0bec41f56
commit a93228c579
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765
4 changed files with 14 additions and 8 deletions

View file

@ -0,0 +1,10 @@
module ObjectVersionsHelper
def attach_existing_fields(version, new_object)
version.object_changes.to_h.each do |k, v|
method_name = "#{k}=".to_sym
if new_object.respond_to?(method_name)
new_object.public_send(method_name, v.last)
end
end
end
end