webhooker 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 12637776cd5504910820de4dbaff8a7c2a19e5f9
4
- data.tar.gz: 7b7a18f01feaaf15acf369364696c152d42f7a82
3
+ metadata.gz: fa012c157d6e655bcff57c6b26f13271f985d15c
4
+ data.tar.gz: 427f3ca404f29df767107703dacccc530214b9cc
5
5
  SHA512:
6
- metadata.gz: cdf60a833c2c20b147895cb67e9909d33c15afcf1468537e2ec8e1b95adef347aa13a329c711124140434a598d53fd540c2e0463363adcd39fa4087dd8c95839
7
- data.tar.gz: 6f631bc02e51954125bbf9c530117b2f7aed189bde476861c80765f0aeaf2f5bbad5ba8542a709cdd49e674145e90f2484df25155e905f3872e46294e6ed4bb6
6
+ metadata.gz: 938bef6ad7061bd233449f6017ee1bd472f209e82ab8ccef88bd8839a89ca5f8c605347b5006f21486bf2077270ec7df73f7398912e84faeb44a8d0567a444ca
7
+ data.tar.gz: ce5f0f1c0668f13e50a23426a80d50b4f30faed92979a3d163210c972dae6699e0b0be03712549e9a32e9a14539109e63463c6f0d15ef3374e851200b70f83fa
data/config/spring.rb CHANGED
@@ -1 +1,2 @@
1
1
  Spring.application_root = 'spec/dummy'
2
+ Spring.watch '../../lib/webhooker'
@@ -5,21 +5,34 @@ module Webhooker
5
5
  module Model
6
6
  extend ActiveSupport::Concern
7
7
 
8
- def _trigger_webhook
9
- attrs = attributes
10
- if self.class.webhook_attributes
11
- attrs = attrs.slice(*self.class.webhook_attributes)
12
- end
8
+ def _trigger_webhook_on_create
9
+ _trigger_webhook :create
10
+ end
13
11
 
14
- if (changes.keys & attrs.keys).present?
15
- data = {
16
- type: self.class.name,
17
- attributes: attributes.as_json,
18
- changes: changes.slice(*attrs.keys).as_json,
19
- }
20
- Subscriber.find_each do |subscriber|
21
- TriggerJob.perform_later subscriber, data
12
+ def _trigger_webhook_on_update
13
+ filtered_changes =
14
+ if self.class.webhook_attributes
15
+ changes.slice(*self.class.webhook_attributes)
16
+ else
17
+ changes
22
18
  end
19
+ if filtered_changes.present?
20
+ _trigger_webhook :update, changes: filtered_changes
21
+ end
22
+ end
23
+
24
+ def _trigger_webhook_on_destroy
25
+ _trigger_webhook :destroy
26
+ end
27
+
28
+ def _trigger_webhook action, data = {}
29
+ data = {
30
+ resource: model_name.element,
31
+ action: action.to_s,
32
+ attributes: attributes.as_json,
33
+ }.merge(data)
34
+ Subscriber.find_each do |subscriber|
35
+ TriggerJob.perform_later subscriber, data
23
36
  end
24
37
  end
25
38
 
@@ -27,8 +40,10 @@ module Webhooker
27
40
  attr_accessor :webhook_attributes
28
41
 
29
42
  def webhooks *args
30
- after_save :_trigger_webhook
31
43
  options = args.extract_options!
44
+ (options[:on] || %i(create update destroy)).each do |action|
45
+ send :"after_#{action}", :"_trigger_webhook_on_#{action}"
46
+ end
32
47
  @webhook_attributes = options[:attributes].try(:map, &:to_s)
33
48
  end
34
49
  end
@@ -1,3 +1,3 @@
1
1
  module Webhooker
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webhooker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kayhide
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-14 00:00:00.000000000 Z
11
+ date: 2015-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails