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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b88f4d48ae4b7758ab569a17cc9eda783f55457
4
- data.tar.gz: 69fe16ade2ea0daf253428f6fb780bc6e2bf82d2
3
+ metadata.gz: 742a90cca44dd0b2f507c27e846d11c0d047ea44
4
+ data.tar.gz: 932c46302c78abb4e7d1f9f8eedd77696f5b210b
5
5
  SHA512:
6
- metadata.gz: 71449baa37d765212df0bff3b1dc766ed146e2241769e7fdb6dc7ec992ddabfe8f191d019e81a9c44536945205213a282ca521dce6efcf1e96b6ef36af08789e
7
- data.tar.gz: 696c42006ed41665c296fa06e5bfb8f071afdfa2bbd6b0d0e23901ffb972e4a71d995272c193be3d70c4ae61700f0505c8a094d04029c351281b2518da665e75
6
+ metadata.gz: a16ef2815d2d67a8ba97024244302154c027a59ea6f4441bb7fee25e1c310e6435da9da758033f764a8d129b877182172547ebf7efc417ac2f9786e4e2cd9706
7
+ data.tar.gz: b7111ccbd9a3555339e17480f8b2e408767eef23ce645c12bf4321574031fbb8ddb9a663ffeaf045e63a1ad572458b18437f2597b31afd8ef25d177a405672b0
@@ -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
- configuration = default_configuration.update(options)
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: 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)
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
@@ -1,3 +1,3 @@
1
1
  module Notifyor
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -1,3 +1,5 @@
1
1
  class User < ActiveRecord::Base
2
- notifyor
2
+ notifyor messages: {
3
+ create: -> (model) { "Benutzer mit der ID: #{model.id} wurde im System angelegt" }
4
+ }, only: [:create, :update]
3
5
  end
Binary file
@@ -94,3 +94,88 @@ Migrating to CreateUsers (20160404044940)
94
94
   (0.1ms) begin transaction
95
95
  SQL (1.2ms) DELETE FROM "users" WHERE "users"."id" = ? [["id", 12]]
96
96
   (1.6ms) commit transaction
97
+ User Load (0.2ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
98
+  (0.2ms) begin transaction
99
+ SQL (0.9ms) INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-05 18:00:24.280508"], ["updated_at", "2016-04-05 18:00:24.280508"]]
100
+  (2.2ms) commit transaction
101
+  (0.1ms) begin transaction
102
+ SQL (1.0ms) 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
+  (1.9ms) commit transaction
104
+  (0.1ms) begin transaction
105
+ SQL (0.5ms) 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
+  (1.9ms) commit transaction
107
+  (0.2ms) begin transaction
108
+ SQL (0.5ms) 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
+  (1.9ms) commit transaction
110
+  (0.1ms) begin transaction
111
+ SQL (0.5ms) 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
+  (2.2ms) commit transaction
113
+  (0.2ms) begin transaction
114
+ SQL (1.5ms) 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
+  (2.3ms) commit transaction
116
+  (0.3ms) begin transaction
117
+ SQL (1.4ms) 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
+  (2.1ms) commit transaction
119
+  (0.5ms) begin transaction
120
+ SQL (1.4ms) INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-05 18:19:45.533232"], ["updated_at", "2016-04-05 18:19:45.533232"]]
121
+  (2.2ms) commit transaction
122
+  (0.3ms) begin transaction
123
+ SQL (0.8ms) 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
+  (2.2ms) commit transaction
125
+  (0.2ms) begin transaction
126
+ SQL (1.0ms) 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
+  (2.3ms) commit transaction
128
+  (0.4ms) begin transaction
129
+ SQL (0.7ms) 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
+  (2.4ms) commit transaction
131
+  (0.3ms) begin transaction
132
+ SQL (1.2ms) 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
+  (2.3ms) commit transaction
134
+ User Load (0.3ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
135
+ User Load (0.2ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
136
+  (0.3ms) begin transaction
137
+ SQL (0.7ms) 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
+  (1.8ms) commit transaction
139
+  (0.3ms) begin transaction
140
+ SQL (1.4ms) 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
+  (9.3ms) commit transaction
142
+  (0.1ms) begin transaction
143
+  (0.3ms) begin transaction
144
+ SQL (0.6ms) 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
+  (2.3ms) commit transaction
146
+  (0.2ms) begin transaction
147
+ SQL (0.9ms) 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
+  (2.1ms) commit transaction
149
+ User Load (0.6ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
150
+  (0.6ms) begin transaction
151
+  (0.7ms) rollback transaction
152
+ User Load (0.8ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
153
+  (0.4ms) begin transaction
154
+  (0.1ms) rollback transaction
155
+ User Load (0.3ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
156
+  (0.3ms) begin transaction
157
+ SQL (0.7ms) 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
+  (2.3ms) commit transaction
159
+ User Load (0.8ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
160
+ User Load (0.6ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
161
+ User Load (0.6ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
162
+  (0.3ms) begin transaction
163
+ SQL (2.0ms) UPDATE "users" SET "email" = ?, "updated_at" = ? WHERE "users"."id" = ? [["email", "erwinschens"], ["updated_at", "2016-04-05 18:47:01.481115"], ["id", 4]]
164
+  (2.5ms) commit transaction
165
+ User Load (0.5ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
166
+  (0.2ms) begin transaction
167
+ SQL (1.2ms) DELETE FROM "users" WHERE "users"."id" = ? [["id", 29]]
168
+  (2.3ms) commit transaction
169
+ User Load (0.6ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
170
+  (0.2ms) begin transaction
171
+ SQL (0.6ms) DELETE FROM "users" WHERE "users"."id" = ? [["id", 28]]
172
+  (2.1ms) commit transaction
173
+ User Load (0.5ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
174
+  (0.3ms) begin transaction
175
+  (0.3ms) commit transaction
176
+  (0.3ms) begin transaction
177
+ SQL (3.1ms) INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?) [["created_at", "2016-04-05 18:51:43.543751"], ["updated_at", "2016-04-05 18:51:43.543751"]]
178
+  (2.9ms) commit transaction
179
+ User Load (0.4ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
180
+  (0.4ms) begin transaction
181
+  (0.2ms) commit transaction
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifyor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erwin Schens