module Shrine::Plugins::Mirroring::FileMethods

  1. lib/shrine/plugins/mirroring.rb

Public Instance methods

delete(mirror: true)

Mirrors delete to other mirror storages.

[show source]
    # File lib/shrine/plugins/mirroring.rb
 98 def delete(mirror: true)
 99   result = super()
100   trigger_mirror_delete if mirror
101   result
102 end
mirror_delete()

Deletes the file from each mirror storage.

[show source]
    # File lib/shrine/plugins/mirroring.rb
124 def mirror_delete
125   each_mirror do |mirror|
126     self.class.new(id: id, storage: mirror).delete
127   end
128 end
mirror_delete_background()

Calls mirror delete block.

[show source]
    # File lib/shrine/plugins/mirroring.rb
117 def mirror_delete_background
118   fail Error, "mirror delete block is not registered" unless shrine_class.mirror_delete_block
119 
120   shrine_class.mirror_delete_block.call(self)
121 end
mirror_upload(**options)

Uploads the file to each mirror storage.

[show source]
   # File lib/shrine/plugins/mirroring.rb
82 def mirror_upload(**options)
83   previously_opened = opened?
84 
85   each_mirror do |mirror|
86     rewind if opened?
87 
88     shrine_class.upload(self, mirror, **options, location: id, close: false, action: :mirror)
89   end
90 ensure
91   if opened? && !previously_opened
92     close
93     @io = nil
94   end
95 end
mirror_upload_background(**options)

Calls mirror upload block.

[show source]
   # File lib/shrine/plugins/mirroring.rb
75 def mirror_upload_background(**options)
76   fail Error, "mirror upload block is not registered" unless shrine_class.mirror_upload_block
77 
78   shrine_class.mirror_upload_block.call(self, **options)
79 end
trigger_mirror_delete()

Mirrors delete if mirrors are defined. Calls mirror block if registered, otherwise mirrors synchronously.

[show source]
    # File lib/shrine/plugins/mirroring.rb
106 def trigger_mirror_delete
107   return unless shrine_class.mirrors[storage_key] && shrine_class.mirror_delete?
108 
109   if shrine_class.mirror_delete_block
110     mirror_delete_background
111   else
112     mirror_delete
113   end
114 end
trigger_mirror_upload(**options)

Mirrors upload if mirrors are defined. Calls mirror block if registered, otherwise mirrors synchronously.

[show source]
   # File lib/shrine/plugins/mirroring.rb
64 def trigger_mirror_upload(**options)
65   return unless shrine_class.mirrors[storage_key] && shrine_class.mirror_upload?
66 
67   if shrine_class.mirror_upload_block
68     mirror_upload_background(**options)
69   else
70     mirror_upload(**options)
71   end
72 end