communique 0.0.3 → 0.0.4
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 +4 -4
- data/lib/communique/configuration.rb +1 -0
- data/lib/communique/version.rb +1 -1
- data/lib/communique.rb +35 -7
- data/spec/communique_spec.rb +33 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 774bcaa4e9e2bec498fa64ed09171d390e84aa19
|
4
|
+
data.tar.gz: 300cb9f363f5a590e50b4252c62dc7e14d6159d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b88e73ec989d41c2e7afd8cf388c1384a53b151027a13d57e9faac9c16d7ceab96b04391ae93ac3ae160f1620c6d570190230471626666715f702bdfda55615
|
7
|
+
data.tar.gz: b6dc54ce9f0ccee9012b25ede6bc86ceb35e989d78d03d8ee262dd36725027e703ca98839cee64aed3ecef6c5b5306b254b96fe6e9bb4629cf85278d97b39119
|
data/lib/communique/version.rb
CHANGED
data/lib/communique.rb
CHANGED
@@ -10,13 +10,14 @@ module Communique
|
|
10
10
|
def self.notify(notifiable, action_key, context_info = nil)
|
11
11
|
action = Action.find_or_create_by(key: action_key)
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
if prevent_unseen_duplicates?
|
14
|
+
existing_notification = find_existing_notifications(notifiable, action_key)
|
15
|
+
if existing_notification
|
16
|
+
existing_notification.update_attributes(context_info: context_info)
|
17
|
+
return existing_notification.id.to_s
|
18
|
+
end
|
19
|
+
end
|
20
|
+
notification = create_notification(notifiable, context_info, action_key, action)
|
20
21
|
Handler.external_services notification
|
21
22
|
|
22
23
|
notification.id.to_s
|
@@ -37,4 +38,31 @@ module Communique
|
|
37
38
|
def self.count_unseen(notifiable)
|
38
39
|
Notification.count_unseen notifiable
|
39
40
|
end
|
41
|
+
|
42
|
+
def self.prevent_unseen_duplicates?
|
43
|
+
!Communique.config.nil? && Communique.config.prevent_unseen_duplicates
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.find_existing_notifications(notifiable, action_key)
|
47
|
+
Notification.where(
|
48
|
+
notifiable: notifiable,
|
49
|
+
action_key: action_key,
|
50
|
+
seen: false
|
51
|
+
).order_by(updated_at: :desc).first
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.create_notification( notifiable, context_info, action_key, action)
|
55
|
+
Notification.create(
|
56
|
+
notifiable: notifiable,
|
57
|
+
context_info: context_info,
|
58
|
+
action_key: action_key,
|
59
|
+
action: action
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
private_class_method(
|
64
|
+
:prevent_unseen_duplicates?,
|
65
|
+
:find_existing_notifications,
|
66
|
+
:create_notification
|
67
|
+
)
|
40
68
|
end
|
data/spec/communique_spec.rb
CHANGED
@@ -21,4 +21,37 @@ describe Communique do
|
|
21
21
|
)
|
22
22
|
end
|
23
23
|
end
|
24
|
+
describe 'config.prevent_unseen_duplicates' do
|
25
|
+
it 'creates notifications when prevent_unseen_duplicates if false' do
|
26
|
+
Communique.configure { |config| config.prevent_unseen_duplicates = false }
|
27
|
+
|
28
|
+
dummy = NotifiableDummy.create
|
29
|
+
2.times do
|
30
|
+
Communique.notify(
|
31
|
+
dummy,
|
32
|
+
'3CPO_fell_down_and_hit_his_head',
|
33
|
+
name: 'broken robot',
|
34
|
+
location: 'nginx caching issue'
|
35
|
+
)
|
36
|
+
end
|
37
|
+
expect(dummy.notifications.count).to be 2
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'updates notifications when prevent_unseen_duplicates if true' do
|
42
|
+
Communique.configure { |config| config.prevent_unseen_duplicates = true }
|
43
|
+
|
44
|
+
dummy = NotifiableDummy.create
|
45
|
+
2.times do
|
46
|
+
Communique.notify(
|
47
|
+
dummy,
|
48
|
+
'3CPO_fell_down_and_hit_his_head',
|
49
|
+
name: 'broken robot',
|
50
|
+
location: 'nginx caching issue'
|
51
|
+
)
|
52
|
+
end
|
53
|
+
expect(dummy.notifications.count).to be 1
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
24
57
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: communique
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Polycarpou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -172,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
172
|
version: '0'
|
173
173
|
requirements: []
|
174
174
|
rubyforge_project:
|
175
|
-
rubygems_version: 2.4.
|
175
|
+
rubygems_version: 2.4.5.1
|
176
176
|
signing_key:
|
177
177
|
specification_version: 4
|
178
178
|
summary: Simple way to store warnings and errors affecting users as messages. Stored
|