notification-settings 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,30 +1,28 @@
1
- require 'notification-handler'
2
- require 'active_support'
3
-
4
- module NotificationSettings
5
- module NotificationScopes
6
-
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
- include NotificationSettings::NotificationScopes::InstanceMethods
11
- end
12
-
13
- module InstanceMethods
14
-
15
- def method_missing m, *args
16
- if m.to_s[/(.+)_category/]
17
- where category: $1.singularize.classify
18
- else
19
- super
20
- end
21
- end
22
-
23
- def respond_to? m, include_private = false
24
- super || m.to_s[/(.+)_category/]
25
- end
26
-
27
- end
28
-
29
- end
30
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'notification-handler'
4
+ require 'active_support'
5
+
6
+ module NotificationSettings
7
+ module NotificationScopes
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ include NotificationSettings::NotificationScopes::InstanceMethods
12
+ end
13
+
14
+ module InstanceMethods
15
+ def method_missing(method, *args)
16
+ if method.to_s[/(.+)_category/]
17
+ where(category: $1.singularize.classify)
18
+ else
19
+ super
20
+ end
21
+ end
22
+
23
+ def respond_to_missing?(method, include_private = false)
24
+ super || method.to_s[/(.+)_category/]
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,28 +1,60 @@
1
- require 'active_support'
2
-
3
- module NotificationSettings
4
- module SettingLibrary
5
-
6
- extend ActiveSupport::Concern
7
-
8
- included do
9
- include NotificationSettings::SettingLibrary::InstanceMethods
10
- end
11
-
12
- module InstanceMethods
13
-
14
- def status
15
- 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
16
- default = 'idle'
17
- elsif self.object.respond_to?(NotificationSettings.configuration.last_seen) && ( Time.now - self.object.send(NotificationSettings.configuration.last_seen) ).round >= NotificationSettings.configuration.offline_after
18
- default = 'offline'
19
- else
20
- 'online'
21
- end
22
- self[:status] || default
23
- end
24
-
25
- end
26
-
27
- end
28
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support'
4
+
5
+ module NotificationSettings
6
+ module SettingLibrary
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ include NotificationSettings::SettingLibrary::InstanceMethods
11
+ end
12
+
13
+ module InstanceMethods
14
+ def status
15
+ if idle? && !offline?
16
+ default = 'idle'
17
+ elsif offline?
18
+ default = 'offline'
19
+ else
20
+ 'online'
21
+ end
22
+ self[:status] || default
23
+ end
24
+
25
+ private
26
+
27
+ def idle?
28
+ return unless time_since_last_seen_round
29
+
30
+ time_since_last_seen_round >= idle_after
31
+ end
32
+
33
+ def offline?
34
+ return unless time_since_last_seen_round
35
+
36
+ time_since_last_seen_round >= offline_after
37
+ end
38
+
39
+ def time_since_last_seen_round
40
+ time_since_last_seen&.round
41
+ end
42
+
43
+ def time_since_last_seen
44
+ return unless object.respond_to?(
45
+ NotificationSettings.configuration.last_seen
46
+ )
47
+
48
+ Time.now - object.send(NotificationSettings.configuration.last_seen)
49
+ end
50
+
51
+ def idle_after
52
+ NotificationSettings.configuration.idle_after
53
+ end
54
+
55
+ def offline_after
56
+ NotificationSettings.configuration.offline_after
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,42 +1,50 @@
1
- require 'active_support'
2
-
3
- module NotificationSettings
4
- module Subscribable
5
-
6
- extend ActiveSupport::Concern
7
-
8
- included do
9
- has_many :notification_subscriptions, as: :subscribable, class_name: 'NotificationSettings::Subscription', dependent: :destroy
10
- has_many :notification_subscribers, through: :notification_subscriptions, source: :subscriber
11
-
12
- include NotificationSettings::Subscribable::InstanceMethods
13
- end
14
-
15
- module InstanceMethods
16
-
17
- def notify_subscribers options = {}
18
- options[:object] = self
19
- subscribers = notify_dependents options.delete(:dependents)
20
- self.notification_subscribers&.each { |subscriber| subscribers << subscriber }
21
- subscribers.to_a.uniq&.each do |subscriber|
22
- subscriber.notify options
23
- end
24
- end
25
-
26
- def notify_dependents dependents
27
- subscribers = []
28
- dependents ||= self.notification_dependents
29
- dependents&.each { |dependent| dependent.notification_subscribers&.each { |subscriber| subscribers << subscriber } }
30
- subscribers
31
- end
32
-
33
- private
34
-
35
- def notification_dependents
36
- []
37
- end
38
-
39
- end
40
-
41
- end
42
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support'
4
+
5
+ module NotificationSettings
6
+ module Subscribable
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ has_many :notification_subscriptions,
11
+ as: :subscribable,
12
+ class_name: 'NotificationSettings::Subscription',
13
+ dependent: :destroy
14
+ has_many :notification_subscribers,
15
+ through: :notification_subscriptions, source: :subscriber
16
+
17
+ include NotificationSettings::Subscribable::InstanceMethods
18
+ end
19
+
20
+ module InstanceMethods
21
+ def notify_subscribers(options = {})
22
+ options[:object] = self
23
+ subscribers = notify_dependents(options.delete(:dependents))
24
+ notification_subscribers&.each do |subscriber|
25
+ subscribers << subscriber
26
+ end
27
+ subscribers.to_a.uniq&.each do |subscriber|
28
+ subscriber.notify(options)
29
+ end
30
+ end
31
+
32
+ def notify_dependents(dependents)
33
+ subscribers = []
34
+ dependents ||= notification_dependents
35
+ dependents&.each do |dependent|
36
+ dependent.notification_subscribers&.each do |subscriber|
37
+ subscribers << subscriber
38
+ end
39
+ end
40
+ subscribers
41
+ end
42
+
43
+ private
44
+
45
+ def notification_dependents
46
+ []
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,30 +1,35 @@
1
- require 'active_support'
2
-
3
- module NotificationSettings
4
- module Subscriber
5
-
6
- extend ActiveSupport::Concern
7
-
8
- included do
9
- has_many :notification_subscriptions, as: :subscriber, class_name: 'NotificationSettings::Subscription', dependent: :destroy
10
- has_many :notification_subscribables, through: :notification_subscriptions, source: :subscribable
11
-
12
- include NotificationSettings::Subscriber::InstanceMethods
13
- end
14
-
15
- module InstanceMethods
16
-
17
- def subscribe subscribable, options = {}
18
- options[:subscribable] = subscribable
19
- self.notification_subscriptions.create options
20
- end
21
-
22
- def unsubscribe subscribable
23
- subscription = self.notification_subscriptions.find_by subscribable_id: subscribable.id, subscribable_type: subscribable.class.name
24
- subscription.destroy
25
- end
26
-
27
- end
28
-
29
- end
30
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support'
4
+
5
+ module NotificationSettings
6
+ module Subscriber
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ has_many :notification_subscriptions,
11
+ as: :subscriber,
12
+ class_name: 'NotificationSettings::Subscription',
13
+ dependent: :destroy
14
+ has_many :notification_subscribables,
15
+ through: :notification_subscriptions, source: :subscribable
16
+
17
+ include NotificationSettings::Subscriber::InstanceMethods
18
+ end
19
+
20
+ module InstanceMethods
21
+ def subscribe(subscribable, options = {})
22
+ options[:subscribable] = subscribable
23
+ notification_subscriptions.create(options)
24
+ end
25
+
26
+ def unsubscribe(subscribable)
27
+ subscription = notification_subscriptions.find_by(
28
+ subscribable_id: subscribable.id,
29
+ subscribable_type: subscribable.class.name
30
+ )
31
+ subscription.destroy
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,25 +1,23 @@
1
- require 'active_support'
2
-
3
- module NotificationSettings
4
- module SubscriptionLibrary
5
-
6
- extend ActiveSupport::Concern
7
-
8
- included do
9
- after_create_commit :create_notification_setting
10
-
11
- include NotificationSettings::SubscriptionLibrary::InstanceMethods
12
- end
13
-
14
- module InstanceMethods
15
-
16
- private
17
-
18
- def create_notification_setting
19
- self.notification_setting.create!
20
- end
21
-
22
- end
23
-
24
- end
25
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support'
4
+
5
+ module NotificationSettings
6
+ module SubscriptionLibrary
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ after_create_commit :create_notification_setting
11
+
12
+ include NotificationSettings::SubscriptionLibrary::InstanceMethods
13
+ end
14
+
15
+ module InstanceMethods
16
+ private
17
+
18
+ def create_notification_setting
19
+ notification_setting.create!
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,26 +1,27 @@
1
- require 'active_support'
2
-
3
- module NotificationSettings
4
- module Target
5
-
6
- extend ActiveSupport::Concern
7
-
8
- included do
9
- has_one :notification_setting, as: :object, class_name: 'NotificationSettings::Setting', dependent: :destroy
10
- before_create :create_notification_setting
11
-
12
- include NotificationSettings::Target::InstanceMethods
13
- end
14
-
15
- module InstanceMethods
16
-
17
- private
18
-
19
- def create_notification_setting
20
- self.build_notification_setting
21
- end
22
-
23
- end
24
-
25
- end
26
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support'
4
+
5
+ module NotificationSettings
6
+ module Target
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ has_one :notification_setting,
11
+ as: :object,
12
+ class_name: 'NotificationSettings::Setting',
13
+ dependent: :destroy
14
+ before_create :create_notification_setting
15
+
16
+ include NotificationSettings::Target::InstanceMethods
17
+ end
18
+
19
+ module InstanceMethods
20
+ private
21
+
22
+ def create_notification_setting
23
+ build_notification_setting
24
+ end
25
+ end
26
+ end
27
+ end
metadata CHANGED
@@ -1,99 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notification-settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.5
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Hübotter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-25 00:00:00.000000000 Z
11
+ date: 2018-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: railties
14
+ name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
19
+ version: '5.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '5.0'
26
+ version: '5.2'
27
27
  - !ruby/object:Gem::Dependency
28
- name: activerecord
28
+ name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.0'
33
+ version: '5.2'
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: '5.0'
40
+ version: '5.2'
41
41
  - !ruby/object:Gem::Dependency
42
- name: activesupport
42
+ name: notification-handler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: '5.0'
47
+ version: 1.2.6
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: '5.0'
54
+ version: 1.2.6
55
55
  - !ruby/object:Gem::Dependency
56
- name: notification-handler
56
+ name: railties
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '='
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 1.2.5
61
+ version: '5.2'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '='
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 1.2.5
68
+ version: '5.2'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '3.7'
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '3.7'
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rubocop
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '0.52'
89
+ version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
95
109
  - !ruby/object:Gem::Version
96
- version: '0.52'
110
+ version: '0'
97
111
  description: Integrates with your authentication solution to craft a personalized
98
112
  user notification platform.
99
113
  email: me@jonhue.me
@@ -101,13 +115,11 @@ executables: []
101
115
  extensions: []
102
116
  extra_rdoc_files: []
103
117
  files:
104
- - CHANGELOG.md
105
118
  - LICENSE
106
119
  - README.md
107
120
  - app/models/notification_settings/setting.rb
108
121
  - app/models/notification_settings/subscription.rb
109
122
  - lib/generators/notification_settings/install_generator.rb
110
- - lib/generators/templates/install/README.md
111
123
  - lib/generators/templates/install/initializer.rb
112
124
  - lib/generators/templates/install/notifications_migration.rb.erb
113
125
  - lib/notification-settings.rb
@@ -132,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
144
  requirements:
133
145
  - - ">="
134
146
  - !ruby/object:Gem::Version
135
- version: '2.3'
147
+ version: 2.2.2
136
148
  required_rubygems_version: !ruby/object:Gem::Requirement
137
149
  requirements:
138
150
  - - ">="
@@ -140,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
152
  version: '0'
141
153
  requirements: []
142
154
  rubyforge_project:
143
- rubygems_version: 2.7.4
155
+ rubygems_version: 2.7.6
144
156
  signing_key:
145
157
  specification_version: 4
146
158
  summary: Integrates with your authentication solution to craft a personalized user