1# frozen_string_literal: true
2
3module FileStoreMounter
4  extend ActiveSupport::Concern
5
6  class_methods do
7    def mount_file_store_uploader(uploader)
8      mount_uploader(:file, uploader)
9
10      # This hook is a no-op when the file is uploaded after_commit
11      after_save :update_file_store, if: :saved_change_to_file?
12    end
13  end
14
15  def update_file_store
16    # The file.object_store is set during `uploader.store!` and `uploader.migrate!`
17    update_column(:file_store, file.object_store)
18  end
19end
20