module Webhooker::Model

Public Instance Methods

_trigger_webhook(action, data = {}) click to toggle source
# File lib/webhooker/model.rb, line 28
def _trigger_webhook action, data = {}
  data = {
    resource: model_name.singular,
    action: action.to_s,
    attributes: send(*self.class.webhook_attributes_method).as_json,
  }.merge(data)
  Subscriber.find_each do |subscriber|
    TriggerJob.perform_later subscriber, data
  end
end
_trigger_webhook_on_create() click to toggle source
# File lib/webhooker/model.rb, line 8
def _trigger_webhook_on_create
  _trigger_webhook :create
end
_trigger_webhook_on_destroy() click to toggle source
# File lib/webhooker/model.rb, line 24
def _trigger_webhook_on_destroy
  _trigger_webhook :destroy
end
_trigger_webhook_on_update() click to toggle source
# File lib/webhooker/model.rb, line 12
def _trigger_webhook_on_update
  filtered_changes =
    if self.class.webhook_attributes
      changes.slice(*self.class.webhook_attributes)
    else
      changes
    end
  if filtered_changes.present?
    _trigger_webhook :update, changes: filtered_changes.as_json
  end
end