unotifier 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/unotifier/version.rb +1 -1
- data/lib/unotifier.rb +27 -21
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c47b889fda3eebd43870746eec2eaf08e17c5deb8f0fd33088526bd3cda9c30
|
4
|
+
data.tar.gz: e879c1e1a6ee421a493b6fb27bbe6f6b1575553fd5f4eac2f8af707caa0af228
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f46b3e1bf12f9f72d4514c7f16f74343872539f2b33d8dd2b16836fc21e7232a9bf63724c53ec8c05d0dcd0043613bf6f04dccbc0eb92bab3eff9acf1ee8548
|
7
|
+
data.tar.gz: 41d3b96af73fb7747876b8cdfb5770c996404535f9c0449a40587063b6ac68086f4eaf858be05a8ed64c3cd54493645f9a86b7ba77919ba135006e1cbc8a335c
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
unotifier (0.1.
|
4
|
+
unotifier (0.1.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -38,10 +38,10 @@ DEPENDENCIES
|
|
38
38
|
bundler (~> 1.17)
|
39
39
|
byebug
|
40
40
|
i18n
|
41
|
-
unotifier!
|
42
41
|
pry
|
43
42
|
rake (~> 10.0)
|
44
43
|
rspec (~> 3.0)
|
44
|
+
unotifier!
|
45
45
|
|
46
46
|
BUNDLED WITH
|
47
47
|
1.17.1
|
data/lib/unotifier/version.rb
CHANGED
data/lib/unotifier.rb
CHANGED
@@ -69,7 +69,6 @@ module UNotifier
|
|
69
69
|
def self.notify(key, target, params = {})
|
70
70
|
user_settings = target.notification_settings[key]
|
71
71
|
user_settings ||= "external"
|
72
|
-
config = load_notification!(key)
|
73
72
|
locale_key = locale_key_for(key, params)
|
74
73
|
urgency = urgency_for(key, params)
|
75
74
|
|
@@ -83,29 +82,36 @@ module UNotifier
|
|
83
82
|
notification.save!
|
84
83
|
|
85
84
|
notify_with = []
|
85
|
+
notify_with += configuration.site_providers if !params[:external_only] && notify_onsite?(notification, user_settings)
|
86
|
+
notify_with += configuration.external_providers if !params[:onsite_only] && notify_external?(notification, user_settings)
|
87
|
+
notify_with.each { |p| p.notify(notification) }
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.notify_onsite(key, target, params)
|
91
|
+
notify(key, target, params.merge(onsite_only: true))
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.notify_external(key, target, params)
|
95
|
+
notify(key, target, params.merge(external_only: true))
|
96
|
+
end
|
86
97
|
|
87
|
-
|
98
|
+
private
|
99
|
+
|
100
|
+
def self.notify_onsite?(notification, user_settings)
|
101
|
+
return false if notification.urgency == "optional" && user_settings == "off"
|
102
|
+
notification.target.online?
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.notify_external?(notification, user_settings)
|
106
|
+
case notification.urgency
|
88
107
|
when "immediate"
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
if notification.target.online?
|
93
|
-
notify_with += configuration.site_providers
|
94
|
-
elsif user_settings == "external"
|
95
|
-
notify_with += configuration.external_providers
|
96
|
-
end
|
97
|
-
when "optional"
|
98
|
-
if user_settings != "off"
|
99
|
-
if notification.target.online?
|
100
|
-
notify_with += configuration.site_providers
|
101
|
-
elsif user_settings == "external"
|
102
|
-
notify_with += configuration.external_providers
|
103
|
-
end
|
104
|
-
end
|
108
|
+
true
|
109
|
+
when "regular", "optional"
|
110
|
+
user_settings == "external" && !notification.target.online?
|
105
111
|
when "onsite"
|
106
|
-
|
112
|
+
false
|
113
|
+
else
|
114
|
+
false
|
107
115
|
end
|
108
|
-
|
109
|
-
notify_with.each { |p| p.notify(notification) }
|
110
116
|
end
|
111
117
|
end
|