notification-settings 1.0.0.beta8 → 1.0.0.beta9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/notification_settings/notification_library.rb +45 -36
- data/lib/notification_settings/notification_scopes.rb +18 -8
- data/lib/notification_settings/setting_library.rb +18 -8
- data/lib/notification_settings/subscriber.rb +1 -2
- data/lib/notification_settings/subscription_library.rb +17 -7
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a96b455489b18330a958d378c99aa07dfbc858c25f3dd5ebc4228496f02e8b77
|
4
|
+
data.tar.gz: d5d0533972dfcc08f5d5c319a9039b12d5fde349e16d9145f4ee7a5207fd338d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1187ae4d6b1216cd9d240707b33847eda8e2a8ea8116f7586ccd812ca7d8f047f96ec1e797ee00a939b434d3cbfc4c58d4620363a6f7deede9d212eb1017f5eb
|
7
|
+
data.tar.gz: 2f075eff8cf618128fa87f8a11cf2175653bea835fc9fbb1b3f536f0bae1e2edbc2e54cb1fe4b90a51929fe0b993b4bd4a841a53aa9e5f7ac6647ba5538a4cc6
|
@@ -1,59 +1,68 @@
|
|
1
1
|
module NotificationSettings
|
2
2
|
module NotificationLibrary
|
3
3
|
|
4
|
-
|
4
|
+
extend ActiveSupport::Concern
|
5
5
|
|
6
|
-
|
6
|
+
included do
|
7
|
+
before_create :validate_create
|
8
|
+
belongs_to :subscription, class_name: 'NotificationSettings::Subscription', optional: true
|
7
9
|
|
8
|
-
|
9
|
-
self[:category] || NotificationRenderer.configuration.default_category
|
10
|
+
include NotificationSettings::NotificationLibrary::InstanceMethods
|
10
11
|
end
|
11
12
|
|
12
|
-
|
13
|
+
module InstanceMethods
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
def category
|
16
|
+
self[:category] || NotificationRenderer.configuration.default_category
|
17
|
+
end
|
16
18
|
|
17
|
-
|
18
|
-
# Status
|
19
|
-
valid = false if NotificationSettings.configuration.do_not_notify_statuses.include?(self.target.notification_setting.status)
|
19
|
+
private
|
20
20
|
|
21
|
-
|
22
|
-
valid =
|
23
|
-
## Category
|
24
|
-
valid = false if !self.target.notification_setting.category_settings.dig(self.category.to_sym, :enabled)
|
25
|
-
end
|
21
|
+
def validate_create
|
22
|
+
valid = true
|
26
23
|
|
27
|
-
|
28
|
-
|
24
|
+
if self.target.notification_setting.present?
|
25
|
+
# Status
|
26
|
+
valid = false if NotificationSettings.configuration.do_not_notify_statuses.include?(self.target.notification_setting.status)
|
27
|
+
|
28
|
+
# Settings
|
29
|
+
valid = false if !self.target.notification_setting.settings.dig(:enabled)
|
30
|
+
## Category
|
31
|
+
valid = false if !self.target.notification_setting.category_settings.dig(self.category.to_sym, :enabled)
|
32
|
+
end
|
29
33
|
|
30
|
-
|
31
|
-
|
34
|
+
valid
|
35
|
+
end
|
36
|
+
|
37
|
+
def validate_push
|
38
|
+
valid = true
|
32
39
|
|
33
|
-
|
34
|
-
|
35
|
-
|
40
|
+
if self.target.notification_setting.present?
|
41
|
+
# Status
|
42
|
+
valid = false if NotificationSettings.configuration.do_not_push_statuses.include?(self.target.notification_setting.status)
|
36
43
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
44
|
+
# Settings
|
45
|
+
if self.push.kind_of?(Array)
|
46
|
+
self.push.each do |pusher|
|
47
|
+
valid = false if !self.target.notification_setting.settings.dig(pusher.to_sym) || ( !self.target.notification_setting.settings.dig(:index) && self.target.notification_setting.settings.dig(pusher.to_sym).nil? )
|
48
|
+
## Category
|
49
|
+
valid = false if !self.target.notification_setting.category_settings.dig(self.category.to_sym, pusher.to_sym) || ( !self.target.notification_setting.category_settings.dig(self.category.to_sym, :index) && self.target.notification_setting.category_settings.dig(self.category.to_sym, pusher.to_sym).nil? )
|
50
|
+
end
|
51
|
+
else
|
52
|
+
valid = false if !self.target.notification_setting.settings.dig(self.push.to_sym) || ( !self.target.notification_setting.settings.dig(:index) && self.target.notification_setting.settings.dig(self.push.to_sym).nil? )
|
41
53
|
## Category
|
42
|
-
valid = false if !self.target.notification_setting.category_settings.dig(self.category.to_sym,
|
54
|
+
valid = false if !self.target.notification_setting.category_settings.dig(self.category.to_sym, self.push.to_sym) || ( !self.target.notification_setting.category_settings.dig(self.category.to_sym, :index) && self.target.notification_setting.category_settings.dig(self.category.to_sym, self.push.to_sym).nil? )
|
43
55
|
end
|
44
|
-
else
|
45
|
-
valid = false if !self.target.notification_setting.settings.dig(self.push.to_sym) || ( !self.target.notification_setting.settings.dig(:index) && self.target.notification_setting.settings.dig(self.push.to_sym).nil? )
|
46
|
-
## Category
|
47
|
-
valid = false if !self.target.notification_setting.category_settings.dig(self.category.to_sym, self.push.to_sym) || ( !self.target.notification_setting.category_settings.dig(self.category.to_sym, :index) && self.target.notification_setting.category_settings.dig(self.category.to_sym, self.push.to_sym).nil? )
|
48
56
|
end
|
57
|
+
|
58
|
+
valid
|
49
59
|
end
|
50
60
|
|
51
|
-
|
52
|
-
|
61
|
+
def initialize_pusher
|
62
|
+
return unless validate_push
|
63
|
+
super
|
64
|
+
end
|
53
65
|
|
54
|
-
def initialize_pusher
|
55
|
-
return unless validate_push
|
56
|
-
super
|
57
66
|
end
|
58
67
|
|
59
68
|
end
|
@@ -1,16 +1,26 @@
|
|
1
1
|
module NotificationSettings
|
2
2
|
module NotificationScopes
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
super
|
9
|
-
end
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include NotificationSettings::NotificationScopes::InstanceMethods
|
10
8
|
end
|
11
9
|
|
12
|
-
|
13
|
-
|
10
|
+
module InstanceMethods
|
11
|
+
|
12
|
+
def method_missing m, *args
|
13
|
+
if m.to_s[/(.+)_category/]
|
14
|
+
where category: $1.singularize.classify
|
15
|
+
else
|
16
|
+
super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def respond_to? m, include_private = false
|
21
|
+
super || m.to_s[/(.+)_category/]
|
22
|
+
end
|
23
|
+
|
14
24
|
end
|
15
25
|
|
16
26
|
end
|
@@ -1,15 +1,25 @@
|
|
1
1
|
module NotificationSettings
|
2
2
|
module SettingLibrary
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include NotificationSettings::SettingLibrary::InstanceMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
module InstanceMethods
|
11
|
+
|
12
|
+
def status
|
13
|
+
if self.object.respond_to?(NotificationSettings.configuration.last_seen) && ( Time.now - self.object.send(NotificationSettings.configuration.last_seen) ).round >= NotificationSettings.configuration.idle_after && ( Time.now - self.object.send(NotificationSettings.configuration.last_seen) ).round < NotificationSettings.configuration.offline_after
|
14
|
+
default = 'idle'
|
15
|
+
elsif self.object.respond_to?(NotificationSettings.configuration.last_seen) && ( Time.now - self.object.send(NotificationSettings.configuration.last_seen) ).round >= NotificationSettings.configuration.offline_after
|
16
|
+
default = 'offline'
|
17
|
+
else
|
18
|
+
'online'
|
19
|
+
end
|
20
|
+
self[:status] || default
|
11
21
|
end
|
12
|
-
|
22
|
+
|
13
23
|
end
|
14
24
|
|
15
25
|
end
|
@@ -5,8 +5,7 @@ module NotificationSettings
|
|
5
5
|
has_many :notification_subscribables, through: :notification_subscriptions, source: :subscribable
|
6
6
|
|
7
7
|
def subscribe options = {}
|
8
|
-
options
|
9
|
-
NotificationSettings::Subscription.create options
|
8
|
+
self.notification_subscriptions.create options
|
10
9
|
end
|
11
10
|
|
12
11
|
def unsubscribe subscribable
|
@@ -1,12 +1,22 @@
|
|
1
1
|
module NotificationSettings
|
2
2
|
module SubscriptionLibrary
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
after_create_commit :create_notification_setting
|
8
|
+
|
9
|
+
include NotificationSettings::SubscriptionLibrary::InstanceMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
module InstanceMethods
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def create_notification_setting
|
17
|
+
self.notification_setting.create!
|
18
|
+
end
|
19
|
+
|
10
20
|
end
|
11
21
|
|
12
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notification-settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.beta9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Hübotter
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.0.0.
|
33
|
+
version: 1.0.0.beta9
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.0.0.
|
40
|
+
version: 1.0.0.beta9
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|