module Shrine::Plugins::Backgrounding::AttacherMethods
Public Class Methods
new(**args)
click to toggle source
Inherits global hooks if defined.
Calls superclass method
# File lib/shrine/plugins/backgrounding.rb, line 39 def initialize(**args) super(**args) @destroy_block = self.class.destroy_block @promote_block = self.class.promote_block end
Public Instance Methods
destroy_attached()
click to toggle source
Does a background destroy if destroy block was registered.
Calls superclass method
# File lib/shrine/plugins/backgrounding.rb, line 86 def destroy_attached if destroy? && destroy_block destroy_background else super end end
destroy_background(**options)
click to toggle source
Calls the registered destroy block.
# File lib/shrine/plugins/backgrounding.rb, line 95 def destroy_background(**options) fail Error, "destroy block is not registered" unless destroy_block background_block(destroy_block, **options) end
destroy_block(&block)
click to toggle source
Registers an instance-level deletion hook.
attacher.destroy_block do |attacher| Attachment::DestroyJob.perform_async(attacher.data) end
# File lib/shrine/plugins/backgrounding.rb, line 64 def destroy_block(&block) @destroy_block = block if block @destroy_block end
promote_background(**options)
click to toggle source
Calls the registered promote block.
# File lib/shrine/plugins/backgrounding.rb, line 79 def promote_background(**options) fail Error, "promote block is not registered" unless promote_block background_block(promote_block, **options) end
promote_block(&block)
click to toggle source
Registers an instance-level promotion hook.
attacher.promote_block do |attacher| Attachment::PromoteJob.perform_async( attacher.record, attacher.name attacher.file_data, ) end
# File lib/shrine/plugins/backgrounding.rb, line 54 def promote_block(&block) @promote_block = block if block @promote_block end
promote_cached(**options)
click to toggle source
Does a background promote if promote block was registered.
Calls superclass method
# File lib/shrine/plugins/backgrounding.rb, line 70 def promote_cached(**options) if promote? && promote_block promote_background else super end end
Private Instance Methods
background_block(block, **options)
click to toggle source
# File lib/shrine/plugins/backgrounding.rb, line 103 def background_block(block, **options) if block.arity == 1 block.call(self, **options) else instance_exec(**options, &block) end end