Welcome to mirror list, hosted at ThFree Co, Russian Federation.

file_store_mounter.rb « concerns « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f1ac734635d4f5ad0b81b78d076e624145133622 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

module FileStoreMounter
  extend ActiveSupport::Concern

  class_methods do
    # When `skip_store_file: true` is used, the model MUST explicitly call `store_file_now!`
    def mount_file_store_uploader(uploader, skip_store_file: false)
      mount_uploader(:file, uploader)

      if skip_store_file
        skip_callback :save, :after, :store_file!

        return
      end

      # This hook is a no-op when the file is uploaded after_commit
      after_save :update_file_store, if: :saved_change_to_file?
    end
  end

  def update_file_store
    # The file.object_store is set during `uploader.store!` and `uploader.migrate!`
    update_column(:file_store, file.object_store)
  end

  def store_file_now!
    store_file!
    update_file_store
  end
end