Module: Shrine::Plugins::KithePromotionCallbacks::AttacherMethods

Defined in:
lib/shrine/plugins/kithe_promotion_callbacks.rb

Instance Method Summary collapse

Instance Method Details

#activerecord_after_saveObject

For INLINE promotion, we need to wrap this one in callbacks, in order to be wrapping enough to a) be able to cancel in ‘before`, and b) have `after` actually be running after promotion is complete and persisted.

But we only want to do it here for ‘inline’ promotion mode. For ‘false’ disabled promotion, we don’t want to run callbacks at all; and for ‘background’ this is too early, we want callbacks to run in bg job, not here. AND only if we’re actually promoting, otherwise we don’t want to run callbacks!



64
65
66
67
68
69
70
71
72
# File 'lib/shrine/plugins/kithe_promotion_callbacks.rb', line 64

def activerecord_after_save
  if self.promotion_directives["promote"] == "inline" && promote?
    Shrine::Plugins::KithePromotionCallbacks.with_promotion_callbacks(record) do
      super
    end
  else
    super
  end
end

#atomic_promote(*args, **kwargs) ⇒ Object

Wrapping atomic_promote in callbacks gets background promotion, since the shrine pattern for background job for promotion uses atomic_promote. It also gets any ‘manual’ use of atomic promote, such as from our Asset#promote method.



77
78
79
80
81
# File 'lib/shrine/plugins/kithe_promotion_callbacks.rb', line 77

def atomic_promote(*args, **kwargs)
  Shrine::Plugins::KithePromotionCallbacks.with_promotion_callbacks(record) do
    super
  end
end