notifyor 0.4.1 → 0.4.2

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: 742a90cca44dd0b2f507c27e846d11c0d047ea44
4
- data.tar.gz: 932c46302c78abb4e7d1f9f8eedd77696f5b210b
3
+ metadata.gz: 5e2af9cf84f314cc89eea5ec1bdc046317eb0aa9
4
+ data.tar.gz: d22706af902794c30a161d2cccb016d7a0b04e42
5
5
  SHA512:
6
- metadata.gz: a16ef2815d2d67a8ba97024244302154c027a59ea6f4441bb7fee25e1c310e6435da9da758033f764a8d129b877182172547ebf7efc417ac2f9786e4e2cd9706
7
- data.tar.gz: b7111ccbd9a3555339e17480f8b2e408767eef23ce645c12bf4321574031fbb8ddb9a663ffeaf045e63a1ad572458b18437f2597b31afd8ef25d177a405672b0
6
+ metadata.gz: 130e1deffdfac923fa61893c61fb500734f95f1e60e104d908f84954046c3052ef6dfef145178581e167ef0e459be88c15253bf7982f9c42ca70d4e083829363
7
+ data.tar.gz: 685db19e8f1259cd7ff5f4995d610f124cfaddebb73124cd6d3522ddf4be9558ac374638e0bea88d089c96039de8bb2f2a67368b7ddae3fb2802e701d3d9e9dc
@@ -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
- self.plugin_configuration = default_configuration.deep_merge(options)
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
@@ -1,3 +1,3 @@
1
1
  module Notifyor
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
Binary file
@@ -179,3 +179,17 @@ Migrating to CreateUsers (20160404044940)
179
179
  User Load (0.4ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
180
180
   (0.4ms) begin transaction
181
181
   (0.2ms) commit transaction
182
+  (0.2ms) begin transaction
183
+ SQL (1.5ms) 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
+  (2.2ms) commit transaction
185
+  (0.3ms) begin transaction
186
+ SQL (1.7ms) 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
+  (1.8ms) commit transaction
188
+ User Load (0.5ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
189
+  (0.3ms) begin transaction
190
+ SQL (0.7ms) DELETE FROM "users" WHERE "users"."id" = ? [["id", 4]]
191
+  (2.7ms) commit transaction
192
+ User Load (0.8ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
193
+  (0.3ms) begin transaction
194
+ SQL (1.6ms) 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
+  (2.3ms) 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.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erwin Schens