notification-settings 1.0.0.beta8 → 1.0.0.beta9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c6748a47ba24fc38efaed92649a142f688537217140e71ef268b014ff11616f
4
- data.tar.gz: 035a8c191f4bb07d312dbaa68206f22a13bd8952d202ee6f53c0d4863a5cc1ea
3
+ metadata.gz: a96b455489b18330a958d378c99aa07dfbc858c25f3dd5ebc4228496f02e8b77
4
+ data.tar.gz: d5d0533972dfcc08f5d5c319a9039b12d5fde349e16d9145f4ee7a5207fd338d
5
5
  SHA512:
6
- metadata.gz: 28780647fa27e65dcceef08074e516669d2aad42c2f201f10409374993cc7f6ac7eb2d67ccf1c5c0235397430f6df81397953375a831cc7b8e9bb2f7be38ff2c
7
- data.tar.gz: 53cb1b35d39609291b4f462c1735a2d7235b01e3cce8248133f957c9c3f9ea8e512585cef0f55880ca36773d4236fc81b8112ac3a237a654cccb7de3d7774c3f
6
+ metadata.gz: 1187ae4d6b1216cd9d240707b33847eda8e2a8ea8116f7586ccd812ca7d8f047f96ec1e797ee00a939b434d3cbfc4c58d4620363a6f7deede9d212eb1017f5eb
7
+ data.tar.gz: 2f075eff8cf618128fa87f8a11cf2175653bea835fc9fbb1b3f536f0bae1e2edbc2e54cb1fe4b90a51929fe0b993b4bd4a841a53aa9e5f7ac6647ba5538a4cc6
@@ -1,59 +1,68 @@
1
1
  module NotificationSettings
2
2
  module NotificationLibrary
3
3
 
4
- before_create :validate_create
4
+ extend ActiveSupport::Concern
5
5
 
6
- belongs_to :subscription, class_name: 'NotificationSettings::Subscription', optional: true
6
+ included do
7
+ before_create :validate_create
8
+ belongs_to :subscription, class_name: 'NotificationSettings::Subscription', optional: true
7
9
 
8
- def category
9
- self[:category] || NotificationRenderer.configuration.default_category
10
+ include NotificationSettings::NotificationLibrary::InstanceMethods
10
11
  end
11
12
 
12
- private
13
+ module InstanceMethods
13
14
 
14
- def validate_create
15
- valid = true
15
+ def category
16
+ self[:category] || NotificationRenderer.configuration.default_category
17
+ end
16
18
 
17
- if self.target.notification_setting.present?
18
- # Status
19
- valid = false if NotificationSettings.configuration.do_not_notify_statuses.include?(self.target.notification_setting.status)
19
+ private
20
20
 
21
- # Settings
22
- valid = false if !self.target.notification_setting.settings.dig(:enabled)
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
- valid
28
- end
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
- def validate_push
31
- valid = true
34
+ valid
35
+ end
36
+
37
+ def validate_push
38
+ valid = true
32
39
 
33
- if self.target.notification_setting.present?
34
- # Status
35
- valid = false if NotificationSettings.configuration.do_not_push_statuses.include?(self.target.notification_setting.status)
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
- # Settings
38
- if self.push.kind_of?(Array)
39
- self.push.each do |pusher|
40
- 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? )
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, 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? )
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
- valid
52
- end
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
- def method_missing m, *args
5
- if m.to_s[/(.+)_category/]
6
- where category: $1.singularize.classify
7
- else
8
- super
9
- end
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ include NotificationSettings::NotificationScopes::InstanceMethods
10
8
  end
11
9
 
12
- def respond_to? m, include_private = false
13
- super || m.to_s[/(.+)_category/]
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
- def status
5
- 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
6
- default = 'idle'
7
- elsif self.object.respond_to?(NotificationSettings.configuration.last_seen) && ( Time.now - self.object.send(NotificationSettings.configuration.last_seen) ).round >= NotificationSettings.configuration.offline_after
8
- default = 'offline'
9
- else
10
- 'online'
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
- self[:status] || default
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[:subscriber] = self
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
- after_create_commit :create_notification_setting
5
-
6
- private
7
-
8
- def create_notification_setting
9
- self.notification_setting.create!
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.beta8
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.beta8
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.beta8
40
+ version: 1.0.0.beta9
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement