Module: ActivityNotification::Notifiable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/activity_notification/models/notifiable.rb
Instance Method Summary collapse
- #default_notification_key ⇒ Object
- #default_url_options ⇒ Object
- #notifiable_path(target_type, key = nil) ⇒ Object
- #notification_email_allowed?(target, key) ⇒ Boolean
- #notification_group(target_type, key) ⇒ Object
- #notification_parameters(target_type, key) ⇒ Object
-
#notification_targets(target_type, key) ⇒ Object
Methods to be overriden.
- #notifier(target_type, key) ⇒ Object
-
#notify(target_type, options = {}) ⇒ Object
Wrapper methods of SimpleNotify class methods.
- #notify_all(targets, options = {}) ⇒ Object
- #notify_to(target, options = {}) ⇒ Object
Instance Method Details
#default_notification_key ⇒ Object
132 133 134 |
# File 'lib/activity_notification/models/notifiable.rb', line 132 def default_notification_key "#{to_resource_name}.default" end |
#default_url_options ⇒ Object
19 20 21 |
# File 'lib/activity_notification/models/notifiable.rb', line 19 def Rails.application.routes. end |
#notifiable_path(target_type, key = nil) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/activity_notification/models/notifiable.rb', line 93 def notifiable_path(target_type, key = nil) plural_target_type = target_type.to_s.underscore.pluralize plural_target_type_sym = plural_target_type.to_sym target_typed_method_name = "notifiable_path_for_#{plural_target_type}" if respond_to?(target_typed_method_name) send(target_typed_method_name, key) elsif _notifiable_path[plural_target_type_sym] resolve_value(_notifiable_path[plural_target_type_sym]) else begin polymorphic_path(self) rescue NoMethodError => e raise NotImplementedError, "You have to implement #{self.class}##{__method__}, set :notifiable_path in acts_as_notifiable or set polymorphic_path routing for #{self.class}" rescue ActionController::UrlGenerationError => e 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 end |
#notification_email_allowed?(target, key) ⇒ Boolean
84 85 86 87 88 89 90 91 |
# File 'lib/activity_notification/models/notifiable.rb', line 84 def notification_email_allowed?(target, key) plural_target_type_sym = target.to_resources_name.to_sym if _notification_email_allowed[plural_target_type_sym] resolve_value(_notification_email_allowed[plural_target_type_sym], target, key) else true end end |
#notification_group(target_type, key) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/activity_notification/models/notifiable.rb', line 51 def notification_group(target_type, key) plural_target_type = target_type.to_s.underscore.pluralize plural_target_type_sym = plural_target_type.to_sym target_typed_method_name = "notification_group_for_#{plural_target_type}" if respond_to?(target_typed_method_name) send(target_typed_method_name, key) else resolve_value(_notification_group[plural_target_type_sym]) end end |
#notification_parameters(target_type, key) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/activity_notification/models/notifiable.rb', line 62 def notification_parameters(target_type, key) plural_target_type = target_type.to_s.underscore.pluralize plural_target_type_sym = plural_target_type.to_sym target_typed_method_name = "notification_parameters_for_#{plural_target_type}" if respond_to?(target_typed_method_name) send(target_typed_method_name, key) else resolve_value(_notification_parameters[plural_target_type_sym], key) || {} end end |
#notification_targets(target_type, key) ⇒ Object
Methods to be overriden
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/activity_notification/models/notifiable.rb', line 36 def notification_targets(target_type, key) plural_target_type = target_type.to_s.underscore.pluralize plural_target_type_sym = plural_target_type.to_sym target_typed_method_name = "notification_#{plural_target_type}" if respond_to?(target_typed_method_name) send(target_typed_method_name, key) else if _notification_targets[plural_target_type_sym] resolve_value(_notification_targets[plural_target_type_sym], key) else raise NotImplementedError, "You have to implement #{self.class}##{target_typed_method_name} or set :targets in acts_as_notifiable" end end end |
#notifier(target_type, key) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/activity_notification/models/notifiable.rb', line 73 def notifier(target_type, key) plural_target_type = target_type.to_s.underscore.pluralize plural_target_type_sym = plural_target_type.to_sym target_typed_method_name = "notifier_for_#{plural_target_type}" if respond_to?(target_typed_method_name) send(target_typed_method_name, key) else resolve_value(_notifier[plural_target_type_sym]) end end |
#notify(target_type, options = {}) ⇒ Object
Wrapper methods of SimpleNotify class methods
120 121 122 |
# File 'lib/activity_notification/models/notifiable.rb', line 120 def notify(target_type, = {}) Notification.notify(target_type, self, ) end |
#notify_all(targets, options = {}) ⇒ Object
128 129 130 |
# File 'lib/activity_notification/models/notifiable.rb', line 128 def notify_all(targets, = {}) Notification.notify_all(targets, self, ) end |
#notify_to(target, options = {}) ⇒ Object
124 125 126 |
# File 'lib/activity_notification/models/notifiable.rb', line 124 def notify_to(target, = {}) Notification.notify_to(target, self, ) end |