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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a19987dbc68516497b96678c785b0d4c48f5e99fe0ac2c51b0b361ec389914da
4
- data.tar.gz: d45bd37bd9de65c2d8f27ca48ee390013ab6d15cf68e68e83232f00647ca7bb4
3
+ metadata.gz: 9c47b889fda3eebd43870746eec2eaf08e17c5deb8f0fd33088526bd3cda9c30
4
+ data.tar.gz: e879c1e1a6ee421a493b6fb27bbe6f6b1575553fd5f4eac2f8af707caa0af228
5
5
  SHA512:
6
- metadata.gz: 6371d94478f0443dd43d6b48a46f796bd40d7c5efa8cf2ea249aed2f25d420459e1800d2df991d778c4bae3ab558aab3cab0e30ce8c390c1d980ee807290eba3
7
- data.tar.gz: fef78dda39517b3e146a483a2370add2220949e9258ad685bde790137699a883a1b0c0ee9ddbe853fa4eb3ea276865d95e89899721c62989c986905ec7bcbda4
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.0)
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
@@ -1,3 +1,3 @@
1
1
  module UNotifier
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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
- case urgency
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
- notify_with += configuration.site_providers if notification.target.online?
90
- notify_with += configuration.external_providers
91
- when "regular"
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
- notify_with += configuration.site_providers if notification.target.online?
112
+ false
113
+ else
114
+ false
107
115
  end
108
-
109
- notify_with.each { |p| p.notify(notification) }
110
116
  end
111
117
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unotifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Rashev