activity_notification 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +5 -0
- data/.yardopts +3 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +50 -44
- data/README.md +242 -81
- data/Rakefile +13 -13
- data/activity_notification.gemspec +6 -8
- data/app/controllers/activity_notification/notifications_controller.rb +89 -11
- data/app/controllers/activity_notification/notifications_with_devise_controller.rb +12 -3
- data/app/mailers/activity_notification/mailer.rb +3 -0
- data/gemfiles/Gemfile.rails-4.2 +13 -0
- data/gemfiles/Gemfile.rails-4.2.lock +190 -0
- data/gemfiles/Gemfile.rails-5.0 +14 -0
- data/gemfiles/Gemfile.rails-5.0.lock +201 -0
- data/lib/activity_notification.rb +10 -6
- data/lib/activity_notification/apis/notification_api.rb +137 -27
- data/lib/activity_notification/common.rb +48 -24
- data/lib/activity_notification/config.rb +68 -10
- data/lib/activity_notification/controllers/store_controller.rb +13 -5
- data/lib/activity_notification/helpers/polymorphic_helpers.rb +17 -3
- data/lib/activity_notification/helpers/view_helpers.rb +161 -45
- data/lib/activity_notification/mailers/helpers.rb +121 -83
- data/lib/activity_notification/models/concerns/notifiable.rb +162 -69
- data/lib/activity_notification/models/concerns/notifier.rb +2 -0
- data/lib/activity_notification/models/concerns/target.rb +124 -25
- data/lib/activity_notification/models/notification.rb +168 -4
- data/lib/activity_notification/rails/routes.rb +50 -48
- data/lib/activity_notification/renderable.rb +106 -26
- data/lib/activity_notification/roles/acts_as_notifiable.rb +99 -26
- data/lib/activity_notification/roles/acts_as_notifier.rb +3 -0
- data/lib/activity_notification/roles/acts_as_target.rb +70 -0
- data/lib/activity_notification/version.rb +1 -1
- data/lib/generators/activity_notification/active_record/migration_generator.rb +3 -1
- data/lib/generators/activity_notification/controllers_generator.rb +5 -0
- data/lib/generators/activity_notification/install_generator.rb +7 -3
- data/lib/generators/activity_notification/models/notification_generator.rb +4 -2
- data/lib/generators/activity_notification/views_generator.rb +20 -0
- data/spec/concerns/apis/notification_api_spec.rb +105 -36
- data/spec/concerns/common_spec.rb +1 -1
- data/spec/concerns/models/notifiable_spec.rb +2 -2
- data/spec/concerns/models/notifier_spec.rb +1 -1
- data/spec/concerns/models/target_spec.rb +9 -8
- data/spec/controllers/notifications_controller_shared_examples.rb +101 -28
- data/spec/controllers/notifications_with_devise_controller_spec.rb +14 -4
- data/spec/helpers/view_helpers_spec.rb +3 -3
- data/spec/mailers/mailer_spec.rb +1 -1
- data/spec/models/notification_spec.rb +57 -3
- data/spec/rails_app/app/models/article.rb +1 -2
- data/spec/rails_app/app/models/comment.rb +8 -6
- data/spec/rails_app/app/models/user.rb +1 -1
- data/spec/rails_app/app/views/layouts/_header.html.erb +2 -0
- data/spec/rails_app/config/application.rb +3 -1
- data/spec/rails_app/config/environment.rb +12 -2
- data/spec/rails_app/config/environments/test.rb +11 -2
- data/spec/roles/acts_as_notifiable_spec.rb +2 -2
- data/spec/roles/acts_as_notifier_spec.rb +1 -1
- data/spec/roles/acts_as_target_spec.rb +3 -3
- data/spec/spec_helper.rb +6 -0
- metadata +35 -40
- data/spec/rails_app/app/models/concerns/.keep +0 -0
@@ -1,96 +1,134 @@
|
|
1
1
|
module ActivityNotification
|
2
|
+
# Mailer module of ActivityNotification
|
2
3
|
module Mailers
|
4
|
+
# Provides helper methods for mailer.
|
5
|
+
# Use to resolve parameters from email configuration and send notification email.
|
3
6
|
module Helpers
|
4
7
|
extend ActiveSupport::Concern
|
5
8
|
|
6
9
|
protected
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
# Send notification email with configured options.
|
12
|
+
#
|
13
|
+
# @param [Notification] notification Notification instance
|
14
|
+
# @param [Hash] options Options for email notification
|
15
|
+
def notification_mail(notification, options = {})
|
16
|
+
initialize_from_notification(notification)
|
17
|
+
headers = headers_for(notification.key, options)
|
18
|
+
begin
|
19
|
+
mail headers
|
20
|
+
rescue ActionView::MissingTemplate
|
21
|
+
mail headers.merge(template_name: 'default')
|
22
|
+
end
|
16
23
|
end
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
def headers_for(key, options)
|
24
|
-
if @notifiable.respond_to?(:overriding_notification_email_key) and
|
25
|
-
@notifiable.overriding_notification_email_key(@target, key).present?
|
26
|
-
key = @notifiable.overriding_notification_email_key(@target, key)
|
24
|
+
|
25
|
+
# Initialize instance variables from notification.
|
26
|
+
#
|
27
|
+
# @param [Notification] notification Notification instance
|
28
|
+
def initialize_from_notification(notification)
|
29
|
+
@notification, @target, @notifiable = notification, notification.target, notification.notifiable
|
27
30
|
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
31
|
+
|
32
|
+
# Prepare email header from notification key and options.
|
33
|
+
#
|
34
|
+
# @param [String] key Key of the notification
|
35
|
+
# @param [Hash] options Options for email notification
|
36
|
+
def headers_for(key, options)
|
37
|
+
if @notifiable.respond_to?(:overriding_notification_email_key) and
|
38
|
+
@notifiable.overriding_notification_email_key(@target, key).present?
|
39
|
+
key = @notifiable.overriding_notification_email_key(@target, key)
|
40
|
+
end
|
41
|
+
headers = {
|
42
|
+
subject: subject_for(key),
|
43
|
+
to: mailer_to(@target),
|
44
|
+
from: mailer_from(@notification),
|
45
|
+
reply_to: mailer_reply_to(@notification),
|
46
|
+
template_path: template_paths,
|
47
|
+
template_name: template_name(key)
|
48
|
+
}.merge(options)
|
49
|
+
|
50
|
+
@email = headers[:to]
|
51
|
+
headers
|
52
|
+
end
|
53
|
+
|
54
|
+
# Returns target email address as 'to'.
|
55
|
+
#
|
56
|
+
# @param [Object] target Target instance to notify
|
57
|
+
# @return [String] Target email address as 'to'
|
58
|
+
def mailer_to(target)
|
59
|
+
target.mailer_to
|
60
|
+
end
|
61
|
+
|
62
|
+
# Returns sender email address as 'reply_to'.
|
63
|
+
#
|
64
|
+
# @param [Notification] notification Notification instance
|
65
|
+
# @return [String] Sender email address as 'reply_to'
|
66
|
+
def mailer_reply_to(notification)
|
67
|
+
mailer_sender(notification, :reply_to)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Returns sender email address as 'from'.
|
71
|
+
#
|
72
|
+
# @param [Notification] notification Notification instance
|
73
|
+
# @return [String] Sender email address as 'from'
|
74
|
+
def mailer_from(notification)
|
75
|
+
mailer_sender(notification, :from)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Returns sender email address configured in initializer or mailer class.
|
79
|
+
#
|
80
|
+
# @param [Notification] notification Notification instance
|
81
|
+
# @return [String] Sender email address configured in initializer or mailer class
|
82
|
+
def mailer_sender(notification, sender = :from)
|
83
|
+
default_sender = default_params[sender]
|
84
|
+
if default_sender.present?
|
85
|
+
default_sender.respond_to?(:to_proc) ? instance_eval(&default_sender) : default_sender
|
86
|
+
elsif ActivityNotification.config.mailer_sender.is_a?(Proc)
|
87
|
+
ActivityNotification.config.mailer_sender.call(notification)
|
88
|
+
else
|
89
|
+
ActivityNotification.config.mailer_sender
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Returns template paths to find email view
|
94
|
+
#
|
95
|
+
# @return [Array<String>] Template paths to find email view
|
96
|
+
def template_paths
|
97
|
+
paths = ['activity_notification/mailer/default']
|
98
|
+
paths.unshift("activity_notification/mailer/#{@target.to_resources_name}") if @target.present?
|
99
|
+
paths
|
100
|
+
end
|
101
|
+
|
102
|
+
# Returns template name from notification key
|
103
|
+
#
|
104
|
+
# @param [String] key Key of the notification
|
105
|
+
# @return [String] Template name
|
106
|
+
def template_name(key)
|
107
|
+
key.gsub('.', '/')
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
# Set up a subject doing an I18n lookup.
|
112
|
+
# At first, it attempts to set a subject based on the current mapping:
|
113
|
+
# en:
|
114
|
+
# notification:
|
115
|
+
# {target}:
|
116
|
+
# {key}:
|
117
|
+
# mail_subject: '...'
|
118
|
+
#
|
119
|
+
# If one does not exist, it fallbacks to default:
|
120
|
+
# Notification for #{notification.printable_type}
|
121
|
+
#
|
122
|
+
# @param [String] key Key of the notification
|
123
|
+
# @return [String] Subject of notification email
|
124
|
+
def subject_for(key)
|
125
|
+
k = key.split('.')
|
126
|
+
k.unshift('notification') if k.first != 'notification'
|
127
|
+
k.insert(1, @target.to_resource_name)
|
128
|
+
k = k.join('.')
|
129
|
+
I18n.t(:mail_subject, scope: k,
|
130
|
+
default: ["Notification of #{@notifiable.printable_type}"])
|
61
131
|
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def template_paths
|
65
|
-
paths = ['activity_notification/mailer/default']
|
66
|
-
paths.unshift("activity_notification/mailer/#{@target.to_resources_name}") if @target.present?
|
67
|
-
paths
|
68
|
-
end
|
69
|
-
|
70
|
-
def template_name(key)
|
71
|
-
key.gsub('.', '/')
|
72
|
-
end
|
73
|
-
|
74
|
-
|
75
|
-
# Set up a subject doing an I18n lookup.
|
76
|
-
# At first, it attempts to set a subject based on the current mapping:
|
77
|
-
# en:
|
78
|
-
# notification:
|
79
|
-
# {target}:
|
80
|
-
# {key}:
|
81
|
-
# mail_subject: '...'
|
82
|
-
#
|
83
|
-
# If one does not exist, it fallbacks to default:
|
84
|
-
# Notification for #{notification.printable_type}
|
85
|
-
#
|
86
|
-
def subject_for(key)
|
87
|
-
k = key.split('.')
|
88
|
-
k.unshift('notification') if k.first != 'notification'
|
89
|
-
k.insert(1, @target.to_resource_name)
|
90
|
-
k = k.join('.')
|
91
|
-
I18n.t(:mail_subject, scope: k,
|
92
|
-
default: ["Notification of #{@notifiable.printable_type}"])
|
93
|
-
end
|
94
132
|
|
95
133
|
end
|
96
134
|
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
module ActivityNotification
|
2
|
+
# Notifiable implementation included in notifiable model to be notified, like comments or any other user activities.
|
2
3
|
module Notifiable
|
3
4
|
extend ActiveSupport::Concern
|
5
|
+
# include PolymorphicHelpers to resolve string extentions
|
6
|
+
include ActivityNotification::PolymorphicHelpers
|
4
7
|
|
5
8
|
included do
|
6
9
|
include Common
|
@@ -15,15 +18,21 @@ module ActivityNotification
|
|
15
18
|
set_notifiable_class_defaults
|
16
19
|
end
|
17
20
|
|
21
|
+
# Returns default_url_options for polymorphic_path.
|
22
|
+
# @return [Hash] Rails.application.routes.default_url_options
|
18
23
|
def default_url_options
|
19
24
|
Rails.application.routes.default_url_options
|
20
25
|
end
|
21
26
|
|
22
27
|
class_methods do
|
28
|
+
# Checks if the model includes notifiable and notifiable methods are available.
|
29
|
+
# @return [Boolean] Always true
|
23
30
|
def available_as_notifiable?
|
24
31
|
true
|
25
32
|
end
|
26
33
|
|
34
|
+
# Sets default values to notifiable class fields.
|
35
|
+
# @return [Nil] nil
|
27
36
|
def set_notifiable_class_defaults
|
28
37
|
self._notification_targets = {}
|
29
38
|
self._notification_group = {}
|
@@ -31,111 +40,195 @@ module ActivityNotification
|
|
31
40
|
self._notification_parameters = {}
|
32
41
|
self._notification_email_allowed = {}
|
33
42
|
self._notifiable_path = {}
|
43
|
+
nil
|
34
44
|
end
|
35
45
|
end
|
36
46
|
|
37
|
-
#
|
38
|
-
|
47
|
+
# Returns notification targets from configured field or overriden method.
|
48
|
+
# This method is able to be overriden.
|
49
|
+
#
|
50
|
+
# @param [String] target_type Target type to notify
|
51
|
+
# @param [String] key Key of the notification
|
52
|
+
# @return [Array<Notificaion> | ActiveRecord_AssociationRelation<Notificaion>] Array or database query of the notification targets
|
39
53
|
def notification_targets(target_type, key)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
raise NotImplementedError, "You have to implement #{self.class}##{target_typed_method_name} or set :targets in acts_as_notifiable"
|
50
|
-
end
|
54
|
+
target_typed_method_name = "notification_#{target_type.to_s.to_resources_name}"
|
55
|
+
resolved_parameter = resolve_parameter(
|
56
|
+
target_typed_method_name,
|
57
|
+
_notification_targets[target_type.to_s.to_resources_name.to_sym],
|
58
|
+
nil,
|
59
|
+
key)
|
60
|
+
unless resolved_parameter
|
61
|
+
raise NotImplementedError, "You have to implement #{self.class}##{target_typed_method_name} "\
|
62
|
+
"or set :targets in acts_as_notifiable"
|
51
63
|
end
|
64
|
+
resolved_parameter
|
52
65
|
end
|
53
66
|
|
67
|
+
# Returns group owner of the notification from configured field or overriden method.
|
68
|
+
# This method is able to be overriden.
|
69
|
+
#
|
70
|
+
# @param [String] target_type Target type to notify
|
71
|
+
# @param [String] key Key of the notification
|
72
|
+
# @return [Object] Group owner of the notification
|
54
73
|
def notification_group(target_type, key)
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
else
|
61
|
-
resolve_value(_notification_group[plural_target_type_sym], key)
|
62
|
-
end
|
74
|
+
resolve_parameter(
|
75
|
+
"notification_group_for_#{target_type.to_s.to_resources_name}",
|
76
|
+
_notification_group[target_type.to_s.to_resources_name.to_sym],
|
77
|
+
nil,
|
78
|
+
key)
|
63
79
|
end
|
64
80
|
|
81
|
+
# Returns additional notification parameters from configured field or overriden method.
|
82
|
+
# This method is able to be overriden.
|
83
|
+
#
|
84
|
+
# @param [String] target_type Target type to notify
|
85
|
+
# @param [String] key Key of the notification
|
86
|
+
# @return [Hash] Additional notification parameters
|
65
87
|
def notification_parameters(target_type, key)
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
else
|
72
|
-
resolve_value(_notification_parameters[plural_target_type_sym], key) || {}
|
73
|
-
end
|
88
|
+
resolve_parameter(
|
89
|
+
"notification_parameters_for_#{target_type.to_s.to_resources_name}",
|
90
|
+
_notification_parameters[target_type.to_s.to_resources_name.to_sym],
|
91
|
+
{},
|
92
|
+
key)
|
74
93
|
end
|
75
94
|
|
95
|
+
# Returns notifier of the notification from configured field or overriden method.
|
96
|
+
# This method is able to be overriden.
|
97
|
+
#
|
98
|
+
# @param [String] target_type Target type to notify
|
99
|
+
# @param [String] key Key of the notification
|
100
|
+
# @return [Object] Notifier of the notification
|
76
101
|
def notifier(target_type, key)
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
else
|
83
|
-
resolve_value(_notifier[plural_target_type_sym], key)
|
84
|
-
end
|
102
|
+
resolve_parameter(
|
103
|
+
"notifier_for_#{target_type.to_s.to_resources_name}",
|
104
|
+
_notifier[target_type.to_s.to_resources_name.to_sym],
|
105
|
+
nil,
|
106
|
+
key)
|
85
107
|
end
|
86
108
|
|
109
|
+
# Returns if sending notification email is allowed for the notifiable from configured field or overriden method.
|
110
|
+
# This method is able to be overriden.
|
111
|
+
#
|
112
|
+
# @param [Object] target Target instance to notify
|
113
|
+
# @param [String] key Key of the notification
|
114
|
+
# @return [Boolean] If sending notification email is allowed for the notifiable
|
87
115
|
def notification_email_allowed?(target, key)
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
elsif _notification_email_allowed[plural_target_type_sym]
|
94
|
-
resolve_value(_notification_email_allowed[plural_target_type_sym], target, key)
|
95
|
-
else
|
96
|
-
ActivityNotification.config.email_enabled
|
97
|
-
end
|
116
|
+
resolve_parameter(
|
117
|
+
"notification_email_allowed_for_#{target.class.to_s.to_resources_name}?",
|
118
|
+
_notification_email_allowed[target.class.to_s.to_resources_name.to_sym],
|
119
|
+
ActivityNotification.config.email_enabled,
|
120
|
+
target, key)
|
98
121
|
end
|
99
122
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
123
|
+
# Returns notifiable_path to move after opening notification from configured field or overriden method.
|
124
|
+
# This method is able to be overriden.
|
125
|
+
#
|
126
|
+
# @param [String] target_type Target type to notify
|
127
|
+
# @param [String] key Key of the notification
|
128
|
+
# @return [String] Notifiable path URL to move after opening notification
|
129
|
+
def notifiable_path(target_type, key)
|
130
|
+
resolved_parameter = resolve_parameter(
|
131
|
+
"notifiable_path_for_#{target_type.to_s.to_resources_name}",
|
132
|
+
_notifiable_path[target_type.to_s.to_resources_name.to_sym],
|
133
|
+
nil,
|
134
|
+
key)
|
135
|
+
unless resolved_parameter
|
109
136
|
begin
|
110
|
-
polymorphic_path(self)
|
137
|
+
resolved_parameter = polymorphic_path(self)
|
111
138
|
rescue NoMethodError, ActionController::UrlGenerationError
|
112
|
-
raise NotImplementedError, "You have to implement #{self.class}##{__method__},
|
139
|
+
raise NotImplementedError, "You have to implement #{self.class}##{__method__}, "\
|
140
|
+
"set :notifiable_path in acts_as_notifiable or "\
|
141
|
+
"set polymorphic_path routing for #{self.class}"
|
113
142
|
end
|
114
143
|
end
|
144
|
+
resolved_parameter
|
115
145
|
end
|
116
146
|
|
117
|
-
#
|
118
|
-
#
|
119
|
-
|
120
|
-
#
|
147
|
+
# overriding_notification_email_key is the method to override key definition for Mailer
|
148
|
+
# When respond_to?(overriding_notification_email_key) returns true,
|
149
|
+
# Mailer uses overriding_notification_email_key instead of original key.
|
150
|
+
#
|
121
151
|
# overriding_notification_email_key(target, key)
|
122
152
|
|
123
|
-
|
124
|
-
|
153
|
+
|
154
|
+
# Generates notifications to configured targets with notifiable model.
|
155
|
+
# This method calls NotificationApi#notify internally with self notifiable instance.
|
156
|
+
# @see NotificationApi#notify
|
157
|
+
#
|
158
|
+
# @param [Symbol, String, Class] target_type Type of target
|
159
|
+
# @param [Hash] options Options for notifications
|
160
|
+
# @option options [String] :key (notifiable.default_notification_key) Key of the notification
|
161
|
+
# @option options [Object] :group (nil) Group unit of the notifications
|
162
|
+
# @option options [Object] :notifier (nil) Notifier of the notifications
|
163
|
+
# @option options [Hash] :parameters ({}) Additional parameters of the notifications
|
164
|
+
# @option options [Boolean] :send_email (true) If it sends notification email
|
165
|
+
# @option options [Boolean] :send_later (true) If it sends notification email asynchronously
|
166
|
+
# @return [Array<Notificaion>] Array of generated notifications
|
125
167
|
def notify(target_type, options = {})
|
126
168
|
Notification.notify(target_type, self, options)
|
127
169
|
end
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
170
|
+
|
171
|
+
# Generates notifications to one target.
|
172
|
+
# This method calls NotificationApi#notify_all internally with self notifiable instance.
|
173
|
+
# @see NotificationApi#notify_all
|
174
|
+
#
|
175
|
+
# @param [Array<Object>] targets Targets to send notifications
|
176
|
+
# @param [Hash] options Options for notifications
|
177
|
+
# @option options [String] :key (notifiable.default_notification_key) Key of the notification
|
178
|
+
# @option options [Object] :group (nil) Group unit of the notifications
|
179
|
+
# @option options [Object] :notifier (nil) Notifier of the notifications
|
180
|
+
# @option options [Hash] :parameters ({}) Additional parameters of the notifications
|
181
|
+
# @option options [Boolean] :send_email (true) Whether it sends notification email
|
182
|
+
# @option options [Boolean] :send_later (true) Whether it sends notification email asynchronously
|
183
|
+
# @return [Array<Notificaion>] Array of generated notifications
|
133
184
|
def notify_all(targets, options = {})
|
134
185
|
Notification.notify_all(targets, self, options)
|
135
186
|
end
|
136
187
|
|
188
|
+
# Generates notifications to one target.
|
189
|
+
# This method calls NotificationApi#notify_to internally with self notifiable instance.
|
190
|
+
# @see NotificationApi#notify_to
|
191
|
+
#
|
192
|
+
# @param [Object] target Target to send notifications
|
193
|
+
# @param [Hash] options Options for notifications
|
194
|
+
# @option options [String] :key (notifiable.default_notification_key) Key of the notification
|
195
|
+
# @option options [Object] :group (nil) Group unit of the notifications
|
196
|
+
# @option options [Object] :notifier (nil) Notifier of the notifications
|
197
|
+
# @option options [Hash] :parameters ({}) Additional parameters of the notifications
|
198
|
+
# @option options [Boolean] :send_email (true) Whether it sends notification email
|
199
|
+
# @option options [Boolean] :send_later (true) Whether it sends notification email asynchronously
|
200
|
+
# @return [Notification] Generated notification instance
|
201
|
+
def notify_to(target, options = {})
|
202
|
+
Notification.notify_to(target, self, options)
|
203
|
+
end
|
204
|
+
|
205
|
+
# Returns default key of the notification.
|
206
|
+
# This method is able to be overriden.
|
207
|
+
# "#{to_resource_name}.default" is defined as default key.
|
208
|
+
#
|
209
|
+
# @return [String] Default Key of the notification
|
137
210
|
def default_notification_key
|
138
211
|
"#{to_resource_name}.default"
|
139
212
|
end
|
213
|
+
|
214
|
+
private
|
215
|
+
|
216
|
+
# Used to transform parameter value from configured field or defined method.
|
217
|
+
# @api private
|
218
|
+
#
|
219
|
+
# @param [String] target_typed_method_name Method name overriden for the target type
|
220
|
+
# @param [Object] parameter_field Parameter Configured field in this model
|
221
|
+
# @param [Object] default_value Default parameter value
|
222
|
+
# @param [Array] args Arguments to pass to the method overriden or defined as parameter field
|
223
|
+
# @return [Object] Resolved parameter value
|
224
|
+
def resolve_parameter(target_typed_method_name, parameter_field, default_value, *args)
|
225
|
+
if respond_to?(target_typed_method_name)
|
226
|
+
send(target_typed_method_name, *args)
|
227
|
+
elsif parameter_field
|
228
|
+
resolve_value(parameter_field, *args)
|
229
|
+
else
|
230
|
+
default_value
|
231
|
+
end
|
232
|
+
end
|
140
233
|
end
|
141
234
|
end
|