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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0b21b40fea27da456c9d5861f5186571379f7ef
4
- data.tar.gz: 3e2eaa99002718566ad4b315c5f0455801eb0158
3
+ metadata.gz: 0b88f4d48ae4b7758ab569a17cc9eda783f55457
4
+ data.tar.gz: 69fe16ade2ea0daf253428f6fb780bc6e2bf82d2
5
5
  SHA512:
6
- metadata.gz: 2aab52e0d9708cd1abb8cc591212ee57cb172271586a7ded0370491b99b04b10b0f1c1167f5019224ec6cf10557603e33f2a4b788a58b0b4209a0bfef36b5022
7
- data.tar.gz: 39f3a39d4ee3d0d94d7b8bfca06deb21fe5ae6fe5edd5accdf6c80c7a911bff6e45d682cf3e2faa6fdc0adccdc7b572ce685c7cc4470aa01f0d9c764ca87f3f0
6
+ metadata.gz: 71449baa37d765212df0bff3b1dc766ed146e2241769e7fdb6dc7ec992ddabfe8f191d019e81a9c44536945205213a282ca521dce6efcf1e96b6ef36af08789e
7
+ data.tar.gz: 696c42006ed41665c296fa06e5bfb8f071afdfa2bbd6b0d0e23901ffb972e4a71d995272c193be3d70c4ae61700f0505c8a094d04029c351281b2518da665e75
@@ -8,19 +8,45 @@ module Notifyor
8
8
  end
9
9
 
10
10
  module ClassMethods
11
- attr_accessor :events
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.events = ::Redis::List.new("notifyor:#{self.name.tableize}")
18
- append_callbacks
18
+ self.notifyor_events = ::Redis::List.new("notifyor:#{self.name.tableize}")
19
19
  end
20
20
 
21
- def append_callbacks
22
- self.send(:before_create, -> { self.class.events << I18n.t('notifyor.model.create', model: self.model_name.human) })
23
- self.send(:before_destroy, -> { self.class.events << I18n.t('notifyor.model.delete', model: self.model_name.human) })
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
@@ -1,3 +1,3 @@
1
1
  module Notifyor
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.0"
3
3
  end
Binary file
@@ -83,3 +83,14 @@ Migrating to CreateUsers (20160404044940)
83
83
   (0.2ms) begin transaction
84
84
  SQL (0.5ms) 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
   (2.3ms) commit transaction
86
+  (0.2ms) begin transaction
87
+ SQL (1.0ms) 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
+  (2.1ms) commit transaction
89
+ User Load (0.2ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
90
+  (0.1ms) begin transaction
91
+ SQL (0.4ms) DELETE FROM "users" WHERE "users"."id" = ? [["id", 3]]
92
+  (1.9ms) commit transaction
93
+ User Load (0.4ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
94
+  (0.1ms) begin transaction
95
+ SQL (1.2ms) DELETE FROM "users" WHERE "users"."id" = ? [["id", 12]]
96
+  (1.6ms) 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.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erwin Schens