2019-05-03 08:17:27 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-05 14:23:59 +05:30
|
|
|
module HasDestroyedWebHook
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2023-01-09 12:20:10 +00:00
|
|
|
included { around_destroy :enqueue_destroyed_web_hook }
|
2018-10-05 14:23:59 +05:30
|
|
|
|
|
|
|
def enqueue_destroyed_web_hook
|
|
|
|
type = self.class.name.underscore.to_sym
|
2019-02-19 12:43:08 +05:30
|
|
|
|
|
|
|
if WebHook.active_web_hooks(type).exists?
|
|
|
|
payload = WebHook.generate_payload(type, self)
|
|
|
|
yield
|
2023-01-09 12:20:10 +00:00
|
|
|
WebHook.enqueue_hooks(type, "#{type}_destroyed".to_sym, id: id, payload: payload)
|
2019-02-19 12:43:08 +05:30
|
|
|
else
|
|
|
|
yield
|
|
|
|
end
|
2018-10-05 14:23:59 +05:30
|
|
|
end
|
|
|
|
end
|