Skip to content

Instantly share code, notes, and snippets.

@JamesPaden
Last active March 5, 2019 17:11
Show Gist options
  • Save JamesPaden/76d26f7696bbdcee6e4b002930aa7e4a to your computer and use it in GitHub Desktop.
Save JamesPaden/76d26f7696bbdcee6e4b002930aa7e4a to your computer and use it in GitHub Desktop.
def write_active_migrator_destination_model!
if ActiveMigrator.config.enabled_checker.call(id)
ActiveMigrator.config.metric_incrementer.call("active_migrator.#{active_migrator_source_klass.name}.write_active_migrator_destination_model")
original_record = find_original_model
if original_record
active_migrator_destination_model = original_record.find_active_migrator_destination_model
original_record.transformed_attributes_for_active_migrator.each do |name, value|
active_migrator_destination_model.send(:write_attribute, name, value)
end
active_migrator_destination_model.save!
else
active_migrator_destination_model = find_active_migrator_destination_model
active_migrator_destination_model.destroy unless active_migrator_destination_model.new_record?
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment