notifyor 0.4.0 → 0.4.1
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 -20
- data/lib/notifyor/version.rb +1 -1
- data/spec/test_app/app/models/user.rb +3 -1
- data/spec/test_app/db/development.sqlite3 +0 -0
- data/spec/test_app/log/development.log +85 -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: 742a90cca44dd0b2f507c27e846d11c0d047ea44
|
4
|
+
data.tar.gz: 932c46302c78abb4e7d1f9f8eedd77696f5b210b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a16ef2815d2d67a8ba97024244302154c027a59ea6f4441bb7fee25e1c310e6435da9da758033f764a8d129b877182172547ebf7efc417ac2f9786e4e2cd9706
|
7
|
+
data.tar.gz: b7111ccbd9a3555339e17480f8b2e408767eef23ce645c12bf4321574031fbb8ddb9a663ffeaf045e63a1ad572458b18437f2597b31afd8ef25d177a405672b0
|
data/lib/notifyor/plugin.rb
CHANGED
@@ -5,11 +5,39 @@ 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)
|
8
35
|
end
|
9
36
|
|
10
37
|
module ClassMethods
|
11
38
|
attr_accessor :notifyor_events
|
12
39
|
attr_accessor :notifyor_models
|
40
|
+
attr_accessor :plugin_configuration
|
13
41
|
|
14
42
|
def notifyor(options = {})
|
15
43
|
configure_plugin(options)
|
@@ -19,36 +47,20 @@ module Notifyor
|
|
19
47
|
end
|
20
48
|
|
21
49
|
def configure_plugin(options = {})
|
22
|
-
|
23
|
-
append_callbacks(configuration)
|
50
|
+
self.plugin_configuration = default_configuration.deep_merge(options)
|
24
51
|
end
|
25
52
|
|
26
53
|
def default_configuration
|
27
54
|
{
|
28
55
|
only: [:create, :destroy, :update],
|
29
56
|
messages: {
|
30
|
-
create: I18n.t('notifyor.model.create', model:
|
31
|
-
update: I18n.t('notifyor.model.update', model:
|
32
|
-
destroy: I18n.t('notifyor.model.destroy', model:
|
57
|
+
create: -> (model) { I18n.t('notifyor.model.create', model: model.class.model_name.human) },
|
58
|
+
update: -> (model) { I18n.t('notifyor.model.update', model: model.class.model_name.human) },
|
59
|
+
destroy: -> (model) { I18n.t('notifyor.model.destroy', model: model.class.model_name.human) }
|
33
60
|
}
|
34
61
|
}
|
35
62
|
end
|
36
63
|
|
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
|
50
|
-
end
|
51
|
-
|
52
64
|
end
|
53
65
|
end
|
54
66
|
end
|
data/lib/notifyor/version.rb
CHANGED
Binary file
|
@@ -94,3 +94,88 @@ Migrating to CreateUsers (20160404044940)
|
|
94
94
|
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
95
95
|
[1m[35mSQL (1.2ms)[0m DELETE FROM "users" WHERE "users"."id" = ? [["id", 12]]
|
96
96
|
[1m[36m (1.6ms)[0m [1mcommit transaction[0m
|
97
|
+
[1m[36mUser Load (0.2ms)[0m [1mSELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1[0m
|
98
|
+
[1m[35m (0.2ms)[0m begin transaction
|
99
|
+
[1m[36mSQL (0.9ms)[0m [1mINSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?)[0m [["created_at", "2016-04-05 18:00:24.280508"], ["updated_at", "2016-04-05 18:00:24.280508"]]
|
100
|
+
[1m[35m (2.2ms)[0m commit transaction
|
101
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
102
|
+
[1m[35mSQL (1.0ms)[0m INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-05 18:04:41.987829"], ["updated_at", "2016-04-05 18:04:41.987829"]]
|
103
|
+
[1m[36m (1.9ms)[0m [1mcommit transaction[0m
|
104
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
105
|
+
[1m[35mSQL (0.5ms)[0m INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-05 18:05:44.281350"], ["updated_at", "2016-04-05 18:05:44.281350"]]
|
106
|
+
[1m[36m (1.9ms)[0m [1mcommit transaction[0m
|
107
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
108
|
+
[1m[35mSQL (0.5ms)[0m INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-05 18:06:49.024943"], ["updated_at", "2016-04-05 18:06:49.024943"]]
|
109
|
+
[1m[36m (1.9ms)[0m [1mcommit transaction[0m
|
110
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
111
|
+
[1m[35mSQL (0.5ms)[0m INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-05 18:07:23.055850"], ["updated_at", "2016-04-05 18:07:23.055850"]]
|
112
|
+
[1m[36m (2.2ms)[0m [1mcommit transaction[0m
|
113
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
114
|
+
[1m[35mSQL (1.5ms)[0m INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-05 18:10:52.859359"], ["updated_at", "2016-04-05 18:10:52.859359"]]
|
115
|
+
[1m[36m (2.3ms)[0m [1mcommit transaction[0m
|
116
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
117
|
+
[1m[35mSQL (1.4ms)[0m INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-05 18:19:21.661658"], ["updated_at", "2016-04-05 18:19:21.661658"]]
|
118
|
+
[1m[36m (2.1ms)[0m [1mcommit transaction[0m
|
119
|
+
[1m[35m (0.5ms)[0m begin transaction
|
120
|
+
[1m[36mSQL (1.4ms)[0m [1mINSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?)[0m [["created_at", "2016-04-05 18:19:45.533232"], ["updated_at", "2016-04-05 18:19:45.533232"]]
|
121
|
+
[1m[35m (2.2ms)[0m commit transaction
|
122
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
123
|
+
[1m[35mSQL (0.8ms)[0m INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-05 18:20:31.390529"], ["updated_at", "2016-04-05 18:20:31.390529"]]
|
124
|
+
[1m[36m (2.2ms)[0m [1mcommit transaction[0m
|
125
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
126
|
+
[1m[35mSQL (1.0ms)[0m INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-05 18:20:54.522113"], ["updated_at", "2016-04-05 18:20:54.522113"]]
|
127
|
+
[1m[36m (2.3ms)[0m [1mcommit transaction[0m
|
128
|
+
[1m[36m (0.4ms)[0m [1mbegin transaction[0m
|
129
|
+
[1m[35mSQL (0.7ms)[0m INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-05 18:21:47.990711"], ["updated_at", "2016-04-05 18:21:47.990711"]]
|
130
|
+
[1m[36m (2.4ms)[0m [1mcommit transaction[0m
|
131
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
132
|
+
[1m[35mSQL (1.2ms)[0m INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-05 18:24:43.607938"], ["updated_at", "2016-04-05 18:24:43.607938"]]
|
133
|
+
[1m[36m (2.3ms)[0m [1mcommit transaction[0m
|
134
|
+
[1m[35mUser Load (0.3ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
|
135
|
+
[1m[36mUser Load (0.2ms)[0m [1mSELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1[0m
|
136
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
137
|
+
[1m[35mSQL (0.7ms)[0m INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-05 18:35:50.375698"], ["updated_at", "2016-04-05 18:35:50.375698"]]
|
138
|
+
[1m[36m (1.8ms)[0m [1mcommit transaction[0m
|
139
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
140
|
+
[1m[35mSQL (1.4ms)[0m INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-05 18:37:11.011346"], ["updated_at", "2016-04-05 18:37:11.011346"]]
|
141
|
+
[1m[36m (9.3ms)[0m [1mcommit transaction[0m
|
142
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
143
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
144
|
+
[1m[35mSQL (0.6ms)[0m INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-05 18:41:51.102773"], ["updated_at", "2016-04-05 18:41:51.102773"]]
|
145
|
+
[1m[36m (2.3ms)[0m [1mcommit transaction[0m
|
146
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
147
|
+
[1m[35mSQL (0.9ms)[0m INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-05 18:42:30.160601"], ["updated_at", "2016-04-05 18:42:30.160601"]]
|
148
|
+
[1m[36m (2.1ms)[0m [1mcommit transaction[0m
|
149
|
+
[1m[35mUser Load (0.6ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
|
150
|
+
[1m[36m (0.6ms)[0m [1mbegin transaction[0m
|
151
|
+
[1m[35m (0.7ms)[0m rollback transaction
|
152
|
+
[1m[36mUser Load (0.8ms)[0m [1mSELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1[0m
|
153
|
+
[1m[35m (0.4ms)[0m begin transaction
|
154
|
+
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
155
|
+
[1m[36mUser Load (0.3ms)[0m [1mSELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1[0m
|
156
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
157
|
+
[1m[35mSQL (0.7ms)[0m INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-05 18:45:03.776150"], ["updated_at", "2016-04-05 18:45:03.776150"]]
|
158
|
+
[1m[36m (2.3ms)[0m [1mcommit transaction[0m
|
159
|
+
[1m[36mUser Load (0.8ms)[0m [1mSELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1[0m
|
160
|
+
[1m[35mUser Load (0.6ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
|
161
|
+
[1m[36mUser Load (0.6ms)[0m [1mSELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1[0m
|
162
|
+
[1m[35m (0.3ms)[0m begin transaction
|
163
|
+
[1m[36mSQL (2.0ms)[0m [1mUPDATE "users" SET "email" = ?, "updated_at" = ? WHERE "users"."id" = ?[0m [["email", "erwinschens"], ["updated_at", "2016-04-05 18:47:01.481115"], ["id", 4]]
|
164
|
+
[1m[35m (2.5ms)[0m commit transaction
|
165
|
+
[1m[36mUser Load (0.5ms)[0m [1mSELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1[0m
|
166
|
+
[1m[35m (0.2ms)[0m begin transaction
|
167
|
+
[1m[36mSQL (1.2ms)[0m [1mDELETE FROM "users" WHERE "users"."id" = ?[0m [["id", 29]]
|
168
|
+
[1m[35m (2.3ms)[0m commit transaction
|
169
|
+
[1m[36mUser Load (0.6ms)[0m [1mSELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1[0m
|
170
|
+
[1m[35m (0.2ms)[0m begin transaction
|
171
|
+
[1m[36mSQL (0.6ms)[0m [1mDELETE FROM "users" WHERE "users"."id" = ?[0m [["id", 28]]
|
172
|
+
[1m[35m (2.1ms)[0m commit transaction
|
173
|
+
[1m[36mUser Load (0.5ms)[0m [1mSELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1[0m
|
174
|
+
[1m[35m (0.3ms)[0m begin transaction
|
175
|
+
[1m[36m (0.3ms)[0m [1mcommit transaction[0m
|
176
|
+
[1m[35m (0.3ms)[0m begin transaction
|
177
|
+
[1m[36mSQL (3.1ms)[0m [1mINSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?)[0m [["created_at", "2016-04-05 18:51:43.543751"], ["updated_at", "2016-04-05 18:51:43.543751"]]
|
178
|
+
[1m[35m (2.9ms)[0m commit transaction
|
179
|
+
[1m[36mUser Load (0.4ms)[0m [1mSELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1[0m
|
180
|
+
[1m[35m (0.4ms)[0m begin transaction
|
181
|
+
[1m[36m (0.2ms)[0m [1mcommit transaction[0m
|