2020-08-13 18:10:36 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module FileStoreMounter
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
class_methods do
|
|
|
|
def mount_file_store_uploader(uploader)
|
|
|
|
mount_uploader(:file, uploader)
|
|
|
|
|
2021-10-29 12:14:45 +00:00
|
|
|
# This hook is a no-op when the file is uploaded after_commit
|
2020-08-13 18:10:36 +00:00
|
|
|
after_save :update_file_store, if: :saved_change_to_file?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_file_store
|
2021-10-29 12:14:45 +00:00
|
|
|
# The file.object_store is set during `uploader.store!` and `uploader.migrate!`
|
|
|
|
update_column(:file_store, file.object_store)
|
2020-08-13 18:10:36 +00:00
|
|
|
end
|
|
|
|
end
|