Module: ActiveWebhook::Callbacks

Extended by:
ActiveSupport::Concern
Defined in:
lib/active_webhook/callbacks.rb

Defined Under Namespace

Classes: InvalidCallbackError

Constant Summary collapse

SUPPORTED_CALLBACKS =
%i(created updated deleted).freeze

Instance Method Summary collapse

Instance Method Details

#trigger_created_webhookObject



32
33
34
# File 'lib/active_webhook/callbacks.rb', line 32

def trigger_created_webhook
  trigger_webhook(:created)
end

#trigger_deleted_webhookObject



40
41
42
# File 'lib/active_webhook/callbacks.rb', line 40

def trigger_deleted_webhook
  trigger_webhook(:deleted)
end

#trigger_updated_webhookObject



36
37
38
# File 'lib/active_webhook/callbacks.rb', line 36

def trigger_updated_webhook
  trigger_webhook(:updated) unless previous_changes.empty?
end

#trigger_webhook(key, version: nil, type: 'resource', **context) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/active_webhook/callbacks.rb', line 44

def trigger_webhook(key, version: nil, type: 'resource', **context)
  key = [self.class.name.underscore, key].join("/") unless key.is_a?(String)
  context[:resource_id] ||= id
  context[:resource_type] ||= self.class.name

  ActiveWebhook.trigger(key: key, version: version, type: type, **context)
end