2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-05 04:53:59 -04:00
|
|
|
module HasDestroyedWebHook
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
around_destroy :enqueue_destroyed_web_hook
|
|
|
|
end
|
|
|
|
|
|
|
|
def enqueue_destroyed_web_hook
|
|
|
|
type = self.class.name.underscore.to_sym
|
2019-02-19 02:13:08 -05:00
|
|
|
|
|
|
|
if WebHook.active_web_hooks(type).exists?
|
|
|
|
payload = WebHook.generate_payload(type, self)
|
|
|
|
yield
|
|
|
|
WebHook.enqueue_hooks(type, "#{type}_destroyed".to_sym,
|
|
|
|
id: id,
|
|
|
|
payload: payload
|
|
|
|
)
|
|
|
|
else
|
|
|
|
yield
|
|
|
|
end
|
2018-10-05 04:53:59 -04:00
|
|
|
end
|
|
|
|
end
|