Module: Webhooker::Model

Extended by:
ActiveSupport::Concern
Defined in:
lib/webhooker/model.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#_trigger_webhook(action, data = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# 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_createObject



8
9
10
# File 'lib/webhooker/model.rb', line 8

def _trigger_webhook_on_create
  _trigger_webhook :create
end

#_trigger_webhook_on_destroyObject



24
25
26
# File 'lib/webhooker/model.rb', line 24

def _trigger_webhook_on_destroy
  _trigger_webhook :destroy
end

#_trigger_webhook_on_updateObject



12
13
14
15
16
17
18
19
20
21
22
# 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