4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/generators/harmonia/templates/concerns/photo_syncable.rb', line 4
def sync_photos(pg_records, fm_records, options: {})
attachment = options[:attachment] || 'photo'
container_field = options[:container_field] || 'foto'
filename_field = options[:filename_field] || 'foto_filename'
purge_existing = options[:purge_existing]
pg_records.each do |record|
fm_record = fm_records.find { |r| r.id == record.filemaker_id }
record.send(attachment).purge if record.send(attachment).attached? && purge_existing
next unless fm_record.send(container_field).present?
downloaded_image = URI.parse(fm_record.send(container_field)).open
record.send(attachment).attach(io: downloaded_image, filename: fm_record.send(filename_field))
end
end
|