notifyor 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/notifyor/plugin.rb +17 -29
- data/lib/notifyor/version.rb +1 -1
- data/spec/test_app/db/development.sqlite3 +0 -0
- data/spec/test_app/log/development.log +14 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e2af9cf84f314cc89eea5ec1bdc046317eb0aa9
|
4
|
+
data.tar.gz: d22706af902794c30a161d2cccb016d7a0b04e42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 130e1deffdfac923fa61893c61fb500734f95f1e60e104d908f84954046c3052ef6dfef145178581e167ef0e459be88c15253bf7982f9c42ca70d4e083829363
|
7
|
+
data.tar.gz: 685db19e8f1259cd7ff5f4995d610f124cfaddebb73124cd6d3522ddf4be9558ac374638e0bea88d089c96039de8bb2f2a67368b7ddae3fb2802e701d3d9e9dc
|
data/lib/notifyor/plugin.rb
CHANGED
@@ -5,39 +5,11 @@ module Notifyor
|
|
5
5
|
extend ::ActiveSupport::Concern
|
6
6
|
|
7
7
|
included do
|
8
|
-
after_commit :notifyor_create_callback, on: :create, if: :on_create?
|
9
|
-
after_commit :notifyor_update_callback, on: :update, if: :on_update?
|
10
|
-
after_destroy :notifyor_destroy_callback, if: :on_destroy?
|
11
|
-
end
|
12
|
-
|
13
|
-
def on_create?
|
14
|
-
self.class.plugin_configuration[:only].include? :create
|
15
|
-
end
|
16
|
-
|
17
|
-
def on_update?
|
18
|
-
self.class.plugin_configuration[:only].include? :update
|
19
|
-
end
|
20
|
-
|
21
|
-
def on_destroy?
|
22
|
-
self.class.plugin_configuration[:only].include? :destroy
|
23
|
-
end
|
24
|
-
|
25
|
-
def notifyor_create_callback
|
26
|
-
self.class.notifyor_events << self.class.plugin_configuration[:messages][:create].call(self)
|
27
|
-
end
|
28
|
-
|
29
|
-
def notifyor_update_callback
|
30
|
-
self.class.notifyor_events << self.class.plugin_configuration[:messages][:update].call(self)
|
31
|
-
end
|
32
|
-
|
33
|
-
def notifyor_destroy_callback
|
34
|
-
self.class.notifyor_events << self.class.plugin_configuration[:messages][:destroy].call(self)
|
35
8
|
end
|
36
9
|
|
37
10
|
module ClassMethods
|
38
11
|
attr_accessor :notifyor_events
|
39
12
|
attr_accessor :notifyor_models
|
40
|
-
attr_accessor :plugin_configuration
|
41
13
|
|
42
14
|
def notifyor(options = {})
|
43
15
|
configure_plugin(options)
|
@@ -47,7 +19,23 @@ module Notifyor
|
|
47
19
|
end
|
48
20
|
|
49
21
|
def configure_plugin(options = {})
|
50
|
-
|
22
|
+
configuration = default_configuration.deep_merge(options)
|
23
|
+
append_callbacks(configuration)
|
24
|
+
end
|
25
|
+
|
26
|
+
def append_callbacks(configuration)
|
27
|
+
configuration[:only].each do |action|
|
28
|
+
case action
|
29
|
+
when :create
|
30
|
+
self.after_commit -> { self.class.notifyor_events << configuration[:messages][:create].call(self) }, on: :create, if: -> { configuration[:only].include? :create}
|
31
|
+
when :update
|
32
|
+
self.after_commit -> {self.class.notifyor_events << configuration[:messages][:update].call(self) }, on: :update, if: -> { configuration[:only].include? :update}
|
33
|
+
when :destroy
|
34
|
+
self.before_destroy -> {self.class.notifyor_events << configuration[:messages][:destroy].call(self)}, if: -> { configuration[:only].include? :destroy}
|
35
|
+
else
|
36
|
+
#nop
|
37
|
+
end
|
38
|
+
end
|
51
39
|
end
|
52
40
|
|
53
41
|
def default_configuration
|
data/lib/notifyor/version.rb
CHANGED
Binary file
|
@@ -179,3 +179,17 @@ Migrating to CreateUsers (20160404044940)
|
|
179
179
|
[1m[36mUser Load (0.4ms)[0m [1mSELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1[0m
|
180
180
|
[1m[35m (0.4ms)[0m begin transaction
|
181
181
|
[1m[36m (0.2ms)[0m [1mcommit transaction[0m
|
182
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
183
|
+
[1m[35mSQL (1.5ms)[0m INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-05 19:14:13.047557"], ["updated_at", "2016-04-05 19:14:13.047557"]]
|
184
|
+
[1m[36m (2.2ms)[0m [1mcommit transaction[0m
|
185
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
186
|
+
[1m[35mSQL (1.7ms)[0m INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-05 19:14:43.252506"], ["updated_at", "2016-04-05 19:14:43.252506"]]
|
187
|
+
[1m[36m (1.8ms)[0m [1mcommit transaction[0m
|
188
|
+
[1m[35mUser Load (0.5ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
|
189
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
190
|
+
[1m[35mSQL (0.7ms)[0m DELETE FROM "users" WHERE "users"."id" = ? [["id", 4]]
|
191
|
+
[1m[36m (2.7ms)[0m [1mcommit transaction[0m
|
192
|
+
[1m[35mUser Load (0.8ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
|
193
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
194
|
+
[1m[35mSQL (1.6ms)[0m UPDATE "users" SET "first_name" = ?, "updated_at" = ? WHERE "users"."id" = ? [["first_name", "erwin"], ["updated_at", "2016-04-05 19:15:08.874646"], ["id", 5]]
|
195
|
+
[1m[36m (2.3ms)[0m [1mcommit transaction[0m
|