Module: ActivityNotification::Notifiable
- Extended by:
- ActiveSupport::Concern
- Includes:
- PolymorphicHelpers
- Defined in:
- lib/activity_notification/models/concerns/notifiable.rb
Overview
Notifiable implementation included in notifiable model to be notified, like comments or any other user activities.
Instance Method Summary collapse
-
#default_notification_key ⇒ String
Returns default key of the notification.
-
#default_url_options ⇒ Hash
Returns default_url_options for polymorphic_path.
-
#notifiable_action_cable_allowed?(target, key = nil) ⇒ Boolean
Returns if publishing WebSocket using ActionCable is allowed for the notifiable from configured field or overridden method.
-
#notifiable_action_cable_api_allowed?(target, key = nil) ⇒ Boolean
Returns if publishing WebSocket API using ActionCable is allowed for the notifiable from configured field or overridden method.
-
#notifiable_path(target_type, key = nil) ⇒ String
Returns notifiable_path to move after opening notification from configured field or overridden method.
-
#notification_email_allowed?(target, key = nil) ⇒ Boolean
Returns if sending notification email is allowed for the notifiable from configured field or overridden method.
-
#notification_group(target_type, key = nil) ⇒ Object
Returns group unit of the notifications from configured field or overridden method.
-
#notification_group_expiry_delay(target_type, key = nil) ⇒ Object
Returns group expiry period of the notifications from configured field or overridden method.
-
#notification_key_for_tracked_creation ⇒ String
Returns key of the notification for tracked notifiable creation.
-
#notification_key_for_tracked_update ⇒ String
Returns key of the notification for tracked notifiable update.
-
#notification_parameters(target_type, key = nil) ⇒ Hash
Returns additional notification parameters from configured field or overridden method.
-
#notification_targets(target_type, options = {}) ⇒ Array<Notificaion> | ActiveRecord_AssociationRelation<Notificaion>
Returns notification targets from configured field or overridden method.
-
#notifier(target_type, key = nil) ⇒ Object
Returns notifier of the notification from configured field or overridden method.
-
#notify(target_type, options = {}) ⇒ Array<Notificaion>
(also: #notify_now)
Generates notifications to configured targets with notifiable model.
-
#notify_all(targets, options = {}) ⇒ Array<Notificaion>
(also: #notify_all_now)
Generates notifications to one target.
-
#notify_all_later(targets, options = {}) ⇒ Array<Notificaion>
Generates notifications to one target later by ActiveJob queue.
-
#notify_later(target_type, options = {}) ⇒ Array<Notificaion>
Generates notifications to configured targets with notifiable model later by ActiveJob queue.
-
#notify_later_to(target, options = {}) ⇒ Notification
Generates notifications to one target later by ActiveJob queue.
-
#notify_to(target, options = {}) ⇒ Notification
(also: #notify_now_to)
Generates notifications to one target.
-
#optional_target_names(target_type, key = nil) ⇒ Array<Symbol>
Returns optional_target names of the notification from configured field or overridden method.
-
#optional_targets(target_type, key = nil) ⇒ Array<ActivityNotification::OptionalTarget::Base>
Returns optional_targets of the notification from configured field or overridden method.
-
#printable_notifiable_name(target, key = nil) ⇒ String
Returns printable notifiable model name to show in view or email.
Instance Method Details
#default_notification_key ⇒ String
Returns default key of the notification. This method is able to be overridden. “#to_resource_name.default” is defined as default key.
392 393 394 |
# File 'lib/activity_notification/models/concerns/notifiable.rb', line 392 def default_notification_key "#{to_resource_name}.default" end |
#default_url_options ⇒ Hash
Returns default_url_options for polymorphic_path.
38 39 40 |
# File 'lib/activity_notification/models/concerns/notifiable.rb', line 38 def Rails.application.routes. end |
#notifiable_action_cable_allowed?(target, key = nil) ⇒ Boolean
Returns if publishing WebSocket using ActionCable is allowed for the notifiable from configured field or overridden method. This method is able to be overridden.
165 166 167 168 169 170 171 |
# File 'lib/activity_notification/models/concerns/notifiable.rb', line 165 def notifiable_action_cable_allowed?(target, key = nil) resolve_parameter( "notifiable_action_cable_allowed_for_#{cast_to_resources_name(target.class)}?", _notifiable_action_cable_allowed[cast_to_resources_sym(target.class)], ActivityNotification.config.action_cable_enabled, target, key) end |
#notifiable_action_cable_api_allowed?(target, key = nil) ⇒ Boolean
Returns if publishing WebSocket API using ActionCable is allowed for the notifiable from configured field or overridden method. This method is able to be overridden.
179 180 181 182 183 184 185 |
# File 'lib/activity_notification/models/concerns/notifiable.rb', line 179 def notifiable_action_cable_api_allowed?(target, key = nil) resolve_parameter( "notifiable_action_cable_api_allowed_for_#{cast_to_resources_name(target.class)}?", _notifiable_action_cable_api_allowed[cast_to_resources_sym(target.class)], ActivityNotification.config.action_cable_api_enabled, target, key) end |
#notifiable_path(target_type, key = nil) ⇒ String
Returns notifiable_path to move after opening notification from configured field or overridden method. This method is able to be overridden.
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/activity_notification/models/concerns/notifiable.rb', line 193 def notifiable_path(target_type, key = nil) resolved_parameter = resolve_parameter( "notifiable_path_for_#{cast_to_resources_name(target_type)}", _notifiable_path[cast_to_resources_sym(target_type)], nil, key) unless resolved_parameter begin resolved_parameter = defined?(super) ? super : polymorphic_path(self) rescue NoMethodError, ActionController::UrlGenerationError raise NotImplementedError, "You have to implement #{self.class}##{__method__}, "\ "set :notifiable_path in acts_as_notifiable or "\ "set polymorphic_path routing for #{self.class}" end end resolved_parameter end |
#notification_email_allowed?(target, key = nil) ⇒ Boolean
Returns if sending notification email is allowed for the notifiable from configured field or overridden method. This method is able to be overridden.
151 152 153 154 155 156 157 |
# File 'lib/activity_notification/models/concerns/notifiable.rb', line 151 def notification_email_allowed?(target, key = nil) resolve_parameter( "notification_email_allowed_for_#{cast_to_resources_name(target.class)}?", _notification_email_allowed[cast_to_resources_sym(target.class)], ActivityNotification.config.email_enabled, target, key) end |
#notification_group(target_type, key = nil) ⇒ Object
Returns group unit of the notifications from configured field or overridden method. This method is able to be overridden.
95 96 97 98 99 100 101 |
# File 'lib/activity_notification/models/concerns/notifiable.rb', line 95 def notification_group(target_type, key = nil) resolve_parameter( "notification_group_for_#{cast_to_resources_name(target_type)}", _notification_group[cast_to_resources_sym(target_type)], nil, key) end |
#notification_group_expiry_delay(target_type, key = nil) ⇒ Object
Returns group expiry period of the notifications from configured field or overridden method. This method is able to be overridden.
109 110 111 112 113 114 115 |
# File 'lib/activity_notification/models/concerns/notifiable.rb', line 109 def notification_group_expiry_delay(target_type, key = nil) resolve_parameter( "notification_group_expiry_delay_for_#{cast_to_resources_name(target_type)}", _notification_group_expiry_delay[cast_to_resources_sym(target_type)], nil, key) end |
#notification_key_for_tracked_creation ⇒ String
Returns key of the notification for tracked notifiable creation. This method is able to be overridden. “#to_resource_name.create” is defined as default creation key.
401 402 403 |
# File 'lib/activity_notification/models/concerns/notifiable.rb', line 401 def notification_key_for_tracked_creation "#{to_resource_name}.create" end |
#notification_key_for_tracked_update ⇒ String
Returns key of the notification for tracked notifiable update. This method is able to be overridden. “#to_resource_name.update” is defined as default update key.
410 411 412 |
# File 'lib/activity_notification/models/concerns/notifiable.rb', line 410 def notification_key_for_tracked_update "#{to_resource_name}.update" end |
#notification_parameters(target_type, key = nil) ⇒ Hash
Returns additional notification parameters from configured field or overridden method. This method is able to be overridden.
123 124 125 126 127 128 129 |
# File 'lib/activity_notification/models/concerns/notifiable.rb', line 123 def notification_parameters(target_type, key = nil) resolve_parameter( "notification_parameters_for_#{cast_to_resources_name(target_type)}", _notification_parameters[cast_to_resources_sym(target_type)], {}, key) end |
#notification_targets(target_type, options = {}) ⇒ Array<Notificaion> | ActiveRecord_AssociationRelation<Notificaion>
Returns notification targets from configured field or overridden method. This method is able to be overridden.
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/activity_notification/models/concerns/notifiable.rb', line 75 def notification_targets(target_type, = {}) target_typed_method_name = "notification_#{cast_to_resources_name(target_type)}" resolved_parameter = resolve_parameter( target_typed_method_name, _notification_targets[cast_to_resources_sym(target_type)], nil, ) unless resolved_parameter raise NotImplementedError, "You have to implement #{self.class}##{target_typed_method_name} "\ "or set :targets in acts_as_notifiable" end resolved_parameter end |
#notifier(target_type, key = nil) ⇒ Object
Returns notifier of the notification from configured field or overridden method. This method is able to be overridden.
137 138 139 140 141 142 143 |
# File 'lib/activity_notification/models/concerns/notifiable.rb', line 137 def notifier(target_type, key = nil) resolve_parameter( "notifier_for_#{cast_to_resources_name(target_type)}", _notifier[cast_to_resources_sym(target_type)], nil, key) end |
#notify(target_type, options = {}) ⇒ Array<Notificaion> Also known as: notify_now
Generates notifications to configured targets with notifiable model. This method calls NotificationApi#notify internally with self notifiable instance.
280 281 282 |
# File 'lib/activity_notification/models/concerns/notifiable.rb', line 280 def notify(target_type, = {}) Notification.notify(target_type, self, ) end |
#notify_all(targets, options = {}) ⇒ Array<Notificaion> Also known as: notify_all_now
Generates notifications to one target. This method calls NotificationApi#notify_all internally with self notifiable instance.
321 322 323 |
# File 'lib/activity_notification/models/concerns/notifiable.rb', line 321 def notify_all(targets, = {}) Notification.notify_all(targets, self, ) end |
#notify_all_later(targets, options = {}) ⇒ Array<Notificaion>
Generates notifications to one target later by ActiveJob queue. This method calls NotificationApi#notify_all_later internally with self notifiable instance.
342 343 344 |
# File 'lib/activity_notification/models/concerns/notifiable.rb', line 342 def notify_all_later(targets, = {}) Notification.notify_all_later(targets, self, ) end |
#notify_later(target_type, options = {}) ⇒ Array<Notificaion>
Generates notifications to configured targets with notifiable model later by ActiveJob queue. This method calls NotificationApi#notify_later internally with self notifiable instance.
300 301 302 |
# File 'lib/activity_notification/models/concerns/notifiable.rb', line 300 def notify_later(target_type, = {}) Notification.notify_later(target_type, self, ) end |
#notify_later_to(target, options = {}) ⇒ Notification
Generates notifications to one target later by ActiveJob queue. This method calls NotificationApi#notify_later_to internally with self notifiable instance.
383 384 385 |
# File 'lib/activity_notification/models/concerns/notifiable.rb', line 383 def notify_later_to(target, = {}) Notification.notify_later_to(target, self, ) end |
#notify_to(target, options = {}) ⇒ Notification Also known as: notify_now_to
Generates notifications to one target. This method calls NotificationApi#notify_to internally with self notifiable instance.
362 363 364 |
# File 'lib/activity_notification/models/concerns/notifiable.rb', line 362 def notify_to(target, = {}) Notification.notify_to(target, self, ) end |
#optional_target_names(target_type, key = nil) ⇒ Array<Symbol>
Returns optional_target names of the notification from configured field or overridden method. This method is able to be overridden.
241 242 243 |
# File 'lib/activity_notification/models/concerns/notifiable.rb', line 241 def optional_target_names(target_type, key = nil) optional_targets(target_type, key).map { |optional_target| optional_target.to_optional_target_name } end |
#optional_targets(target_type, key = nil) ⇒ Array<ActivityNotification::OptionalTarget::Base>
Returns optional_targets of the notification from configured field or overridden method. This method is able to be overridden.
227 228 229 230 231 232 233 |
# File 'lib/activity_notification/models/concerns/notifiable.rb', line 227 def optional_targets(target_type, key = nil) resolve_parameter( "optional_targets_for_#{cast_to_resources_name(target_type)}", _optional_targets[cast_to_resources_sym(target_type)], [], key) end |
#printable_notifiable_name(target, key = nil) ⇒ String
Returns printable notifiable model name to show in view or email.
213 214 215 216 217 218 219 |
# File 'lib/activity_notification/models/concerns/notifiable.rb', line 213 def printable_notifiable_name(target, key = nil) resolve_parameter( "printable_notifiable_name_for_#{cast_to_resources_name(target.class)}?", _printable_notifiable_name[cast_to_resources_sym(target.class)], printable_name, target, key) end |