activity_notification 1.4.0 → 1.4.1

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +39 -32
  3. data/Gemfile +0 -3
  4. data/Gemfile.lock +66 -73
  5. data/README.md +190 -184
  6. data/activity_notification.gemspec +2 -3
  7. data/gemfiles/Gemfile.rails-4.2 +7 -1
  8. data/gemfiles/Gemfile.rails-4.2.lock +35 -26
  9. data/gemfiles/Gemfile.rails-5.0 +7 -1
  10. data/gemfiles/Gemfile.rails-5.0.lock +73 -64
  11. data/gemfiles/Gemfile.rails-5.1 +6 -3
  12. data/gemfiles/Gemfile.rails-5.1.lock +77 -74
  13. data/lib/activity_notification/apis/notification_api.rb +3 -3
  14. data/lib/activity_notification/models.rb +1 -1
  15. data/lib/activity_notification/models/concerns/notifiable.rb +1 -1
  16. data/lib/activity_notification/models/concerns/target.rb +1 -1
  17. data/lib/activity_notification/orm/active_record/notification.rb +7 -0
  18. data/lib/activity_notification/orm/mongoid.rb +11 -1
  19. data/lib/activity_notification/orm/mongoid/notification.rb +9 -2
  20. data/lib/activity_notification/orm/mongoid/subscription.rb +1 -1
  21. data/lib/activity_notification/roles/acts_as_notifiable.rb +30 -15
  22. data/lib/activity_notification/version.rb +1 -1
  23. data/spec/rails_app/app/models/admin.rb +1 -1
  24. data/spec/rails_app/app/models/article.rb +1 -1
  25. data/spec/rails_app/app/models/comment.rb +1 -1
  26. data/spec/rails_app/app/models/dummy/dummy_base.rb +10 -2
  27. data/spec/rails_app/app/models/dummy/dummy_group.rb +13 -3
  28. data/spec/rails_app/app/models/dummy/dummy_notifiable.rb +13 -3
  29. data/spec/rails_app/app/models/dummy/dummy_notifier.rb +13 -3
  30. data/spec/rails_app/app/models/dummy/dummy_subscriber.rb +12 -3
  31. data/spec/rails_app/app/models/dummy/dummy_target.rb +14 -3
  32. data/spec/rails_app/app/models/user.rb +1 -1
  33. data/spec/rails_app/config/application.rb +7 -3
  34. data/spec/rails_app/config/environment.rb +1 -1
  35. data/spec/rails_app/config/environments/development.rb +3 -1
  36. data/spec/rails_app/config/environments/test.rb +4 -1
  37. data/spec/roles/acts_as_notifiable_spec.rb +10 -6
  38. data/spec/spec_helper.rb +0 -3
  39. metadata +6 -20
@@ -1,20 +1,7 @@
1
- GIT
2
- remote: git://github.com/plataformatec/devise.git
3
- revision: 83002017ea4761e30796f3b288be9c7d9b870fcd
4
- ref: 83002017
5
- specs:
6
- devise (4.2.1)
7
- bcrypt (~> 3.0)
8
- orm_adapter (~> 0.1)
9
- railties (>= 4.1.0, < 5.2)
10
- responders
11
- warden (~> 1.2.3)
12
-
13
1
  PATH
14
2
  remote: ..
15
3
  specs:
16
- activity_notification (1.4.0)
17
- activerecord (>= 4.2.0)
4
+ activity_notification (1.4.1)
18
5
  i18n (>= 0.5.0)
19
6
  jquery-rails (>= 3.1.1)
20
7
  railties (>= 4.2.0, < 5.2)
@@ -22,39 +9,39 @@ PATH
22
9
  GEM
23
10
  remote: https://rubygems.org/
24
11
  specs:
25
- actioncable (5.1.0)
26
- actionpack (= 5.1.0)
12
+ actioncable (5.1.1)
13
+ actionpack (= 5.1.1)
27
14
  nio4r (~> 2.0)
28
15
  websocket-driver (~> 0.6.1)
29
- actionmailer (5.1.0)
30
- actionpack (= 5.1.0)
31
- actionview (= 5.1.0)
32
- activejob (= 5.1.0)
16
+ actionmailer (5.1.1)
17
+ actionpack (= 5.1.1)
18
+ actionview (= 5.1.1)
19
+ activejob (= 5.1.1)
33
20
  mail (~> 2.5, >= 2.5.4)
34
21
  rails-dom-testing (~> 2.0)
35
- actionpack (5.1.0)
36
- actionview (= 5.1.0)
37
- activesupport (= 5.1.0)
22
+ actionpack (5.1.1)
23
+ actionview (= 5.1.1)
24
+ activesupport (= 5.1.1)
38
25
  rack (~> 2.0)
39
26
  rack-test (~> 0.6.3)
40
27
  rails-dom-testing (~> 2.0)
41
28
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
42
- actionview (5.1.0)
43
- activesupport (= 5.1.0)
29
+ actionview (5.1.1)
30
+ activesupport (= 5.1.1)
44
31
  builder (~> 3.1)
45
32
  erubi (~> 1.4)
46
33
  rails-dom-testing (~> 2.0)
47
34
  rails-html-sanitizer (~> 1.0, >= 1.0.3)
48
- activejob (5.1.0)
49
- activesupport (= 5.1.0)
35
+ activejob (5.1.1)
36
+ activesupport (= 5.1.1)
50
37
  globalid (>= 0.3.6)
51
- activemodel (5.1.0)
52
- activesupport (= 5.1.0)
53
- activerecord (5.1.0)
54
- activemodel (= 5.1.0)
55
- activesupport (= 5.1.0)
38
+ activemodel (5.1.1)
39
+ activesupport (= 5.1.1)
40
+ activerecord (5.1.1)
41
+ activemodel (= 5.1.1)
42
+ activesupport (= 5.1.1)
56
43
  arel (~> 8.0)
57
- activesupport (5.1.0)
44
+ activesupport (5.1.1)
58
45
  concurrent-ruby (~> 1.0, >= 1.0.2)
59
46
  i18n (~> 0.7)
60
47
  minitest (~> 5.1)
@@ -64,17 +51,20 @@ GEM
64
51
  railties (>= 3.0)
65
52
  rspec-rails (>= 2.2)
66
53
  arel (8.0.0)
67
- aws-sdk (2.9.16)
68
- aws-sdk-resources (= 2.9.16)
69
- aws-sdk-core (2.9.16)
54
+ aws-sdk (2.9.19)
55
+ aws-sdk-resources (= 2.9.19)
56
+ aws-sdk-core (2.9.19)
70
57
  aws-sigv4 (~> 1.0)
71
58
  jmespath (~> 1.0)
72
- aws-sdk-resources (2.9.16)
73
- aws-sdk-core (= 2.9.16)
59
+ aws-sdk-resources (2.9.19)
60
+ aws-sdk-core (= 2.9.19)
74
61
  aws-sigv4 (1.0.0)
75
62
  bcrypt (3.1.11)
76
63
  bson (4.2.1)
77
64
  builder (3.2.3)
65
+ bullet (5.5.1)
66
+ activesupport (>= 3.0.0)
67
+ uniform_notifier (~> 1.10.0)
78
68
  concurrent-ruby (1.0.5)
79
69
  coveralls (0.8.21)
80
70
  json (>= 1.8, < 3)
@@ -82,8 +72,18 @@ GEM
82
72
  term-ansicolor (~> 1.3)
83
73
  thor (~> 0.19.4)
84
74
  tins (~> 1.6)
75
+ devise (4.3.0)
76
+ bcrypt (~> 3.0)
77
+ orm_adapter (~> 0.1)
78
+ railties (>= 4.1.0, < 5.2)
79
+ responders
80
+ warden (~> 1.2.3)
85
81
  diff-lcs (1.3)
86
82
  docile (1.1.5)
83
+ dotenv (2.2.1)
84
+ dotenv-rails (2.2.1)
85
+ dotenv (= 2.2.1)
86
+ railties (>= 3.2, < 5.2)
87
87
  erubi (1.6.0)
88
88
  factory_girl (4.8.0)
89
89
  activesupport (>= 3.0.0)
@@ -120,33 +120,33 @@ GEM
120
120
  mini_portile2 (~> 2.1.0)
121
121
  orm_adapter (0.5.0)
122
122
  pg (0.20.0)
123
- rack (2.0.2)
123
+ rack (2.0.3)
124
124
  rack-test (0.6.3)
125
125
  rack (>= 1.0)
126
- rails (5.1.0)
127
- actioncable (= 5.1.0)
128
- actionmailer (= 5.1.0)
129
- actionpack (= 5.1.0)
130
- actionview (= 5.1.0)
131
- activejob (= 5.1.0)
132
- activemodel (= 5.1.0)
133
- activerecord (= 5.1.0)
134
- activesupport (= 5.1.0)
126
+ rails (5.1.1)
127
+ actioncable (= 5.1.1)
128
+ actionmailer (= 5.1.1)
129
+ actionpack (= 5.1.1)
130
+ actionview (= 5.1.1)
131
+ activejob (= 5.1.1)
132
+ activemodel (= 5.1.1)
133
+ activerecord (= 5.1.1)
134
+ activesupport (= 5.1.1)
135
135
  bundler (>= 1.3.0, < 2.0)
136
- railties (= 5.1.0)
136
+ railties (= 5.1.1)
137
137
  sprockets-rails (>= 2.0.0)
138
- rails-controller-testing (1.0.1)
139
- actionpack (~> 5.x)
140
- actionview (~> 5.x)
138
+ rails-controller-testing (1.0.2)
139
+ actionpack (~> 5.x, >= 5.0.1)
140
+ actionview (~> 5.x, >= 5.0.1)
141
141
  activesupport (~> 5.x)
142
- rails-dom-testing (2.0.2)
143
- activesupport (>= 4.2.0, < 6.0)
144
- nokogiri (~> 1.6)
142
+ rails-dom-testing (2.0.3)
143
+ activesupport (>= 4.2.0)
144
+ nokogiri (>= 1.6)
145
145
  rails-html-sanitizer (1.0.3)
146
146
  loofah (~> 2.0)
147
- railties (5.1.0)
148
- actionpack (= 5.1.0)
149
- activesupport (= 5.1.0)
147
+ railties (5.1.1)
148
+ actionpack (= 5.1.1)
149
+ activesupport (= 5.1.1)
150
150
  method_source
151
151
  rake (>= 0.8.7)
152
152
  thor (>= 0.18.1, < 2.0)
@@ -154,23 +154,23 @@ GEM
154
154
  responders (2.4.0)
155
155
  actionpack (>= 4.2.0, < 5.3)
156
156
  railties (>= 4.2.0, < 5.3)
157
- rspec-core (3.5.4)
158
- rspec-support (~> 3.5.0)
159
- rspec-expectations (3.5.0)
157
+ rspec-core (3.6.0)
158
+ rspec-support (~> 3.6.0)
159
+ rspec-expectations (3.6.0)
160
160
  diff-lcs (>= 1.2.0, < 2.0)
161
- rspec-support (~> 3.5.0)
162
- rspec-mocks (3.5.0)
161
+ rspec-support (~> 3.6.0)
162
+ rspec-mocks (3.6.0)
163
163
  diff-lcs (>= 1.2.0, < 2.0)
164
- rspec-support (~> 3.5.0)
165
- rspec-rails (3.5.2)
164
+ rspec-support (~> 3.6.0)
165
+ rspec-rails (3.6.0)
166
166
  actionpack (>= 3.0)
167
167
  activesupport (>= 3.0)
168
168
  railties (>= 3.0)
169
- rspec-core (~> 3.5.0)
170
- rspec-expectations (~> 3.5.0)
171
- rspec-mocks (~> 3.5.0)
172
- rspec-support (~> 3.5.0)
173
- rspec-support (3.5.0)
169
+ rspec-core (~> 3.6.0)
170
+ rspec-expectations (~> 3.6.0)
171
+ rspec-mocks (~> 3.6.0)
172
+ rspec-support (~> 3.6.0)
173
+ rspec-support (3.6.0)
174
174
  simplecov (0.14.1)
175
175
  docile (~> 1.1.0)
176
176
  json (>= 1.8, < 3)
@@ -190,9 +190,10 @@ GEM
190
190
  thor (0.19.4)
191
191
  thread_safe (0.3.6)
192
192
  timecop (0.8.1)
193
- tins (1.13.2)
193
+ tins (1.14.0)
194
194
  tzinfo (1.2.3)
195
195
  thread_safe (~> 0.1)
196
+ uniform_notifier (1.10.0)
196
197
  warden (1.2.7)
197
198
  rack (>= 1.0)
198
199
  websocket-driver (0.6.5)
@@ -209,15 +210,17 @@ DEPENDENCIES
209
210
  activity_notification!
210
211
  ammeter
211
212
  aws-sdk (~> 2)
213
+ bullet
212
214
  coveralls
213
- devise!
215
+ devise (~> 4.3.0)
216
+ dotenv-rails
214
217
  factory_girl_rails (~> 4.8.0)
215
218
  mongoid (>= 4.0.0)
216
219
  mysql2 (~> 0.4.6)
217
220
  pg (~> 0.20.0)
218
- rails (~> 5.1)
221
+ rails (~> 5.1.0)
219
222
  rails-controller-testing
220
- rspec-rails (~> 3.5.2)
223
+ rspec-rails (~> 3.6.0)
221
224
  simplecov (~> 0.14.1)
222
225
  slack-notifier (>= 1.5.1)
223
226
  sqlite3 (~> 1.3.13)
@@ -455,7 +455,7 @@ module ActivityNotification
455
455
  # @param [Integer] limit Limit to query for opened notifications
456
456
  # @return [Integer] Count of group notifications including owner and members
457
457
  def group_notifier_count(limit = ActivityNotification.config.opened_index_limit)
458
- notification = group_member? ? group_owner : self
458
+ notification = group_member? && group_owner.present? ? group_owner : self
459
459
  notification.notifier.present? ? group_member_notifier_count(limit) + 1 : 0
460
460
  end
461
461
 
@@ -464,7 +464,7 @@ module ActivityNotification
464
464
  #
465
465
  # @return [Notificaion] Notification instance of the latest group member notification
466
466
  def latest_group_member
467
- notification = group_member? ? group_owner : self
467
+ notification = group_member? && group_owner.present? ? group_owner : self
468
468
  notification.group_member_exists? ? notification.group_members.latest : self
469
469
  end
470
470
 
@@ -530,7 +530,7 @@ module ActivityNotification
530
530
  # @param [Integer] limit Limit to query for opened notifications
531
531
  # @return [Integer] Count of various members of the notification
532
532
  def meta_group_member_count(opened_member_count_method_name, unopened_member_count_method_name, limit)
533
- notification = group_member? ? group_owner : self
533
+ notification = group_member? && group_owner.present? ? group_owner : self
534
534
  notification.opened? ?
535
535
  notification.send(opened_member_count_method_name, limit) :
536
536
  notification.send(unopened_member_count_method_name)
@@ -17,4 +17,4 @@ module ActivityNotification
17
17
  end
18
18
  end
19
19
 
20
- ActiveRecord::Base.class_eval { include ActivityNotification::Models }
20
+ ActiveRecord::Base.class_eval { include ActivityNotification::Models } if defined?(ActiveRecord::Base)
@@ -348,7 +348,7 @@ module ActivityNotification
348
348
  generated_notifications = generated_notifications_as_notifiable_for(target_type)
349
349
  case dependent
350
350
  when :restrict_with_exception
351
- raise ActiveRecord::DeleteRestrictionError.new("generated_notifications_as_notifiable_for_#{target_type.to_s.pluralize.underscore}") unless generated_notifications.empty?
351
+ ActivityNotification::Notification.raise_delete_restriction_error("generated_notifications_as_notifiable_for_#{target_type.to_s.pluralize.underscore}") unless generated_notifications.empty?
352
352
  when :restrict_with_error
353
353
  unless generated_notifications.empty?
354
354
  record = self.class.human_attribute_name("generated_notifications_as_notifiable_for_#{target_type.to_s.pluralize.underscore}").downcase
@@ -96,7 +96,7 @@ module ActivityNotification
96
96
  # @option options [String] :filtered_by_group_id (nil) Group instance id for filter, valid with :filtered_by_group_type
97
97
  # @option options [String] :filtered_by_key (nil) Key of the notification for filter
98
98
  # @option options [Array|Hash] :custom_filter (nil) Custom notification filter (e.g. ["created_at >= ?", time.hour.ago])
99
- # @return [Array<Notificaion>] All notifications for this target type grouped by targets
99
+ # @return [Hash<Target, Notificaion>] All notifications for this target type grouped by targets
100
100
  def notification_index_map(options = {})
101
101
  all_notifications(options).group_by(&:target)
102
102
  end
@@ -180,6 +180,11 @@ module ActivityNotification
180
180
  pluck(:key).uniq
181
181
  end
182
182
 
183
+ # Raise DeleteRestrictionError for notifications.
184
+ def self.raise_delete_restriction_error(error_text)
185
+ raise ::ActiveRecord::DeleteRestrictionError.new(error_text)
186
+ end
187
+
183
188
  protected
184
189
 
185
190
  # Returns count of group members of the unopened notification.
@@ -200,6 +205,7 @@ module ActivityNotification
200
205
  # This method is designed to cache group by query result to avoid N+1 call.
201
206
  # @api protected
202
207
  #
208
+ # @param [Integer] limit Limit to query for opened notifications
203
209
  # @return [Integer] Count of group members of the opened notification
204
210
  def opened_group_member_count(limit = ActivityNotification.config.opened_index_limit)
205
211
  # Cache group by query result to avoid N+1 call
@@ -233,6 +239,7 @@ module ActivityNotification
233
239
  # This method is designed to cache group by query result to avoid N+1 call.
234
240
  # @api protected
235
241
  #
242
+ # @param [Integer] limit Limit to query for opened notifications
236
243
  # @return [Integer] Count of group member notifiers of the opened notification
237
244
  def opened_group_member_notifier_count(limit = ActivityNotification.config.opened_index_limit)
238
245
  # Cache group by query result to avoid N+1 call
@@ -2,6 +2,15 @@ module ActivityNotification
2
2
  module Association
3
3
  extend ActiveSupport::Concern
4
4
 
5
+ included do
6
+ # Selects filtered notifications by associated instance.
7
+ # @scope class
8
+ # @param [String] name Association name
9
+ # @param [Object] instance Associated instance
10
+ # @return [Mongoid::Criteria<Notificaion>] Database query of filtered notifications
11
+ scope :filtered_by_association, ->(name, instance) { instance.present? ? where({ "#{name}_id" => instance.id, "#{name}_type" => instance.class.name }) : none }
12
+ end
13
+
5
14
  class_methods do
6
15
  # Defines has_many association with ActivityNotification models.
7
16
  # @return [Mongoid::Criteria<Object>] Database query of associated model instances
@@ -49,7 +58,8 @@ module ActivityNotification
49
58
  define_method(name) do |reload = false|
50
59
  reload and self.instance_variable_set("@#{name}", nil)
51
60
  if self.instance_variable_get("@#{name}").blank?
52
- self.instance_variable_set("@#{name}", object_class.where(id_field => self.id, type_field => self.class.name))
61
+ new_value = object_class.where(id_field => self.id, type_field => self.class.name)
62
+ self.instance_variable_set("@#{name}", new_value)
53
63
  end
54
64
  self.instance_variable_get("@#{name}")
55
65
  end
@@ -121,7 +121,7 @@ module ActivityNotification
121
121
  # @scope class
122
122
  # @param [Object] target Target instance for filter
123
123
  # @return [Mongoid::Criteria<Notificaion>] Database query of filtered notifications
124
- scope :filtered_by_target, ->(target) { target.present? ? where(target_id: target.id, target_type: target.class.name) : none }
124
+ scope :filtered_by_target, ->(target) { filtered_by_association("target", target) }
125
125
 
126
126
  # Selects filtered notifications by notifiable instance.
127
127
  # @example Get filtered unopened notificatons of the @user for @comment as notifiable
@@ -129,7 +129,7 @@ module ActivityNotification
129
129
  # @scope class
130
130
  # @param [Object] notifiable Notifiable instance for filter
131
131
  # @return [Mongoid::Criteria<Notificaion>] Database query of filtered notifications
132
- scope :filtered_by_instance, ->(notifiable) { notifiable.present? ? where(notifiable_id: notifiable.id, notifiable_type: notifiable.class.name) : none }
132
+ scope :filtered_by_instance, ->(notifiable) { filtered_by_association("notifiable", notifiable) }
133
133
 
134
134
  # Selects filtered notifications by group instance.
135
135
  # @example Get filtered unopened notificatons of the @user for @article as group
@@ -197,6 +197,11 @@ module ActivityNotification
197
197
  super
198
198
  end
199
199
 
200
+ # Raise DeleteRestrictionError for notifications.
201
+ def self.raise_delete_restriction_error(error_text)
202
+ raise error_text
203
+ end
204
+
200
205
  protected
201
206
 
202
207
  # Returns count of group members of the unopened notification.
@@ -214,6 +219,7 @@ module ActivityNotification
214
219
  # @api protected
215
220
  # @todo Avoid N+1 call
216
221
  #
222
+ # @param [Integer] limit Limit to query for opened notifications
217
223
  # @return [Integer] Count of group members of the opened notification
218
224
  def opened_group_member_count(limit = ActivityNotification.config.opened_index_limit)
219
225
  limit == 0 and return 0
@@ -239,6 +245,7 @@ module ActivityNotification
239
245
  # @api protected
240
246
  # @todo Avoid N+1 call
241
247
  #
248
+ # @param [Integer] limit Limit to query for opened notifications
242
249
  # @return [Integer] Count of group member notifiers of the opened notification
243
250
  def opened_group_member_notifier_count(limit = ActivityNotification.config.opened_index_limit)
244
251
  limit == 0 and return 0
@@ -50,7 +50,7 @@ module ActivityNotification
50
50
  # @scope class
51
51
  # @param [Object] target Target instance for filter
52
52
  # @return [Mongoid::Criteria<Subscription>] Database query of filtered subscriptions
53
- scope :filtered_by_target, ->(target) { target.present? ? where(target_id: target.id, target_type: target.class.name) : none }
53
+ scope :filtered_by_target, ->(target) { filtered_by_association("target", target) }
54
54
 
55
55
  # Includes target instance with query for subscriptions.
56
56
  # @return [Mongoid::Criteria<Subscription>] Database query of subscriptions with target
@@ -3,6 +3,11 @@ module ActivityNotification
3
3
  module ActsAsNotifiable
4
4
  extend ActiveSupport::Concern
5
5
 
6
+ included do
7
+ # Defines private clas methods
8
+ private_class_method :add_tracked_callbacks, :add_tracked_callback, :add_destroy_dependency, :arrange_optional_targets_option
9
+ end
10
+
6
11
  class_methods do
7
12
  # Adds required configurations to notifiable models.
8
13
  #
@@ -107,8 +112,9 @@ module ActivityNotification
107
112
  #
108
113
  # * :tracked
109
114
  # * Adds required callbacks to generate notifications for creation and update of the notifiable model.
110
- # Default callbacks are enabled for [:create, :update].
111
- # You can use :only and :except options as hash for this option.
115
+ # Tracked notifications are disabled as default.
116
+ # When you set true as this :tracked option, default callbacks will be enabled for [:create, :update].
117
+ # You can use :only, :except and other notify options as hash for this option.
112
118
  # @example Add all callbacks to generate notifications for creation and update
113
119
  # # app/models/comment.rb
114
120
  # class Comment < ActiveRecord::Base
@@ -125,7 +131,7 @@ module ActivityNotification
125
131
  # # app/models/comment.rb
126
132
  # class Comment < ActiveRecord::Base
127
133
  # belongs_to :article
128
- # acts_as_notifiable :users, targets: User.all, tracked: { except: [:update] }
134
+ # acts_as_notifiable :users, targets: User.all, tracked: { except: [:update], key: "comment.edited", send_later: false }
129
135
  # end
130
136
  #
131
137
  # * :printable_name or :printable_notifiable_name
@@ -183,6 +189,7 @@ module ActivityNotification
183
189
  # @option options [Symbol, Proc, Hash] :parameters ({}) Additional parameters of the notifications
184
190
  # @option options [Symbol, Proc, Boolean] :email_allowed (ActivityNotification.config.email_enabled) Whether activity_notification sends notification email
185
191
  # @option options [Symbol, Proc, String] :notifiable_path (polymorphic_path(self)) Path to redirect from open or move action of notification controller
192
+ # @option options [Boolean, Hash] :tracked (nil) Flag or parameters for automatic tracked notifications
186
193
  # @option options [Symbol, Proc, String] :printable_name (ActivityNotification::Common.printable_name) Printable notifiable name
187
194
  # @option options [Symbol, Proc] :dependent_notifications (nil) Dependency for notifications to delete generated notifications with this notifiable, [:delete_all, :destroy, :restrict_with_error, :restrict_with_exception, :update_group_and_delete_all, :update_group_and_destroy] are available
188
195
  # @option options [Hash<Class, Hash>] :optional_targets (nil) Optional target configurations with hash of `OptionalTarget` implementation class as key and initializing option parameter as value
@@ -248,21 +255,29 @@ module ActivityNotification
248
255
  elsif tracked_option[:only]
249
256
  tracked_callbacks &= tracked_option.delete(:only)
250
257
  end
251
- if tracked_callbacks.include? :create
252
- if tracked_option.has_key?(:key)
253
- after_create -> { notify target_type, tracked_option }
254
- else
255
- after_create -> { notify target_type, *tracked_option, key: notification_key_for_tracked_creation }
256
- end
258
+ if tracked_option.has_key?(:key)
259
+ add_tracked_callback(tracked_callbacks, :create, ->{ notify target_type, tracked_option })
260
+ add_tracked_callback(tracked_callbacks, :update, ->{ notify target_type, tracked_option })
261
+ else
262
+ add_tracked_callback(tracked_callbacks, :create, ->{ notify target_type, *tracked_option, key: notification_key_for_tracked_creation })
263
+ add_tracked_callback(tracked_callbacks, :update, ->{ notify target_type, *tracked_option, key: notification_key_for_tracked_update })
257
264
  end
258
- if tracked_callbacks.include? :update
259
- if tracked_option.has_key?(:key)
260
- after_update -> { notify target_type, tracked_option }
261
- else
262
- after_update -> { notify target_type, *tracked_option, key: notification_key_for_tracked_update }
265
+ { tracked: tracked_callbacks }
266
+ end
267
+
268
+ # Adds tracked callback.
269
+ # @param [Array<Symbol>] tracked_callbacks Array of tracked callbacks (Array of [:create or :update])
270
+ # @param [Symbol] tracked_action Tracked action (:create or :update)
271
+ # @param [Proc] tracked_proc Proc or lambda function to execute
272
+ def add_tracked_callback(tracked_callbacks, tracked_action, tracked_proc)
273
+ if tracked_callbacks.include? tracked_action
274
+ case tracked_action
275
+ when :create
276
+ after_create tracked_proc
277
+ when :update
278
+ after_update tracked_proc
263
279
  end
264
280
  end
265
- { tracked: tracked_callbacks }
266
281
  end
267
282
 
268
283
  # Adds destroy dependency.