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