notifyor 0.3.2 → 0.4.0
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 +32 -6
- data/lib/notifyor/version.rb +1 -1
- data/spec/test_app/db/development.sqlite3 +0 -0
- data/spec/test_app/log/development.log +11 -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: 0b88f4d48ae4b7758ab569a17cc9eda783f55457
|
4
|
+
data.tar.gz: 69fe16ade2ea0daf253428f6fb780bc6e2bf82d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71449baa37d765212df0bff3b1dc766ed146e2241769e7fdb6dc7ec992ddabfe8f191d019e81a9c44536945205213a282ca521dce6efcf1e96b6ef36af08789e
|
7
|
+
data.tar.gz: 696c42006ed41665c296fa06e5bfb8f071afdfa2bbd6b0d0e23901ffb972e4a71d995272c193be3d70c4ae61700f0505c8a094d04029c351281b2518da665e75
|
data/lib/notifyor/plugin.rb
CHANGED
@@ -8,19 +8,45 @@ module Notifyor
|
|
8
8
|
end
|
9
9
|
|
10
10
|
module ClassMethods
|
11
|
-
attr_accessor :
|
11
|
+
attr_accessor :notifyor_events
|
12
12
|
attr_accessor :notifyor_models
|
13
13
|
|
14
14
|
def notifyor(options = {})
|
15
|
+
configure_plugin(options)
|
15
16
|
self.extend ::Redis::Objects
|
16
17
|
::Notifyor.configuration.notifyor_models.add(self.name)
|
17
|
-
self.
|
18
|
-
append_callbacks
|
18
|
+
self.notifyor_events = ::Redis::List.new("notifyor:#{self.name.tableize}")
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
21
|
+
def configure_plugin(options = {})
|
22
|
+
configuration = default_configuration.update(options)
|
23
|
+
append_callbacks(configuration)
|
24
|
+
end
|
25
|
+
|
26
|
+
def default_configuration
|
27
|
+
{
|
28
|
+
only: [:create, :destroy, :update],
|
29
|
+
messages: {
|
30
|
+
create: I18n.t('notifyor.model.create', model: self.model_name.human),
|
31
|
+
update: I18n.t('notifyor.model.update', model: self.model_name.human),
|
32
|
+
destroy: I18n.t('notifyor.model.destroy', model: self.model_name.human)
|
33
|
+
}
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def append_callbacks(configuration)
|
38
|
+
configuration[:only].each do |action|
|
39
|
+
case action
|
40
|
+
when :create
|
41
|
+
self.after_commit -> { self.class.notifyor_events << configuration[:messages][:create] }, on: :create
|
42
|
+
when :update
|
43
|
+
self.after_commit -> { self.class.notifyor_events << configuration[:messages][:update] }, on: :update
|
44
|
+
when :destroy
|
45
|
+
self.before_destroy -> { self.class.notifyor_events << configuration[:messages][:destroy] }
|
46
|
+
else
|
47
|
+
#nop
|
48
|
+
end
|
49
|
+
end
|
24
50
|
end
|
25
51
|
|
26
52
|
end
|
data/lib/notifyor/version.rb
CHANGED
Binary file
|
@@ -83,3 +83,14 @@ Migrating to CreateUsers (20160404044940)
|
|
83
83
|
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
84
84
|
[1m[35mSQL (0.5ms)[0m INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-05 12:16:43.342740"], ["updated_at", "2016-04-05 12:16:43.342740"]]
|
85
85
|
[1m[36m (2.3ms)[0m [1mcommit transaction[0m
|
86
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
87
|
+
[1m[35mSQL (1.0ms)[0m INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-05 17:43:40.473699"], ["updated_at", "2016-04-05 17:43:40.473699"]]
|
88
|
+
[1m[36m (2.1ms)[0m [1mcommit transaction[0m
|
89
|
+
[1m[35mUser Load (0.2ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
|
90
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
91
|
+
[1m[35mSQL (0.4ms)[0m DELETE FROM "users" WHERE "users"."id" = ? [["id", 3]]
|
92
|
+
[1m[36m (1.9ms)[0m [1mcommit transaction[0m
|
93
|
+
[1m[35mUser Load (0.4ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
|
94
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
95
|
+
[1m[35mSQL (1.2ms)[0m DELETE FROM "users" WHERE "users"."id" = ? [["id", 12]]
|
96
|
+
[1m[36m (1.6ms)[0m [1mcommit transaction[0m
|