Class: Outbox::Notifier
- Inherits:
-
ActionMailer::Base
- Object
- ActionMailer::Base
- Outbox::Notifier
- Extended by:
- DefineInheritableMethod
- Includes:
- NotifierTypes
- Defined in:
- lib/outbox/notifier.rb
Class Method Summary collapse
-
.defaults(value = nil) ⇒ Object
Sets the default options for a message for this Notifier and its descendants.
-
.notifier_name(value = nil) ⇒ Object
(also: notifier_name=)
Returns the name of current notifier.
Instance Method Summary collapse
- #attachments ⇒ Object
-
#headers(args = nil) ⇒ Object
:nodoc:.
-
#initialize(method_name = nil, *args) ⇒ Notifier
constructor
:nodoc:.
-
#message ⇒ Object
The composed Outbox::Message instance.
-
#message_rendered? ⇒ Boolean
Returns true if the message has already been rendered.
-
#process(*args) ⇒ Object
:nodoc:.
-
#render_message(options = {}, &block) ⇒ Object
Renders the message body.
Constructor Details
#initialize(method_name = nil, *args) ⇒ Notifier
:nodoc:
56 57 58 59 60 61 |
# File 'lib/outbox/notifier.rb', line 56 def initialize(method_name = nil, *args) # :nodoc: super() @_message_rendered = false @_message = process(method_name, *args) if method_name end |
Class Method Details
.defaults(value = nil) ⇒ Object
Sets the default options for a message for this Notifier and its descendants. This is similar to ActionMailer’s ‘default` method, but allows you to set options for multiple message types at once:
class UsersNotifier < OutboxNotifier
defaults email: { from: '[email protected]' }, sms: { from: '+12255551234' }
end
26 27 28 29 |
# File 'lib/outbox/notifier.rb', line 26 def defaults(value = nil) self. = .merge(value).freeze if value end |
.notifier_name(value = nil) ⇒ Object Also known as: notifier_name=
Returns the name of current notifier. This method is also being used as a path for a view lookup. If this is an anonymous notifier, this method will return anonymous
instead.
34 35 36 37 38 39 40 |
# File 'lib/outbox/notifier.rb', line 34 def notifier_name(value = nil) if value.nil? mailer_name else self.mailer_name = value end end |
Instance Method Details
#attachments ⇒ Object
102 103 104 105 106 |
# File 'lib/outbox/notifier.rb', line 102 def # Make sure the email message instance exists email({}) if email.nil? email. end |
#headers(args = nil) ⇒ Object
:nodoc:
92 93 94 95 96 97 98 99 100 |
# File 'lib/outbox/notifier.rb', line 92 def headers(args = nil) # :nodoc: # Make sure the email message instance exists email({}) if email.nil? if args email.headers(args) else email end end |
#message ⇒ Object
The composed Outbox::Message instance.
71 72 73 74 |
# File 'lib/outbox/notifier.rb', line 71 def unless @_message end |
#message_rendered? ⇒ Boolean
Returns true if the message has already been rendered.
77 78 79 |
# File 'lib/outbox/notifier.rb', line 77 def @_message_rendered end |
#process(*args) ⇒ Object
:nodoc:
63 64 65 66 67 68 |
# File 'lib/outbox/notifier.rb', line 63 def process(*args) # :nodoc: = @_message super # Make sure we don't ever get a NullMail object. @_message = end |
#render_message(options = {}, &block) ⇒ Object
Renders the message body. This is analagous to ActionMailer’s #mail method, but is not required - it will be called implicitly when the #message object is retrieved.
84 85 86 87 88 89 90 |
# File 'lib/outbox/notifier.rb', line 84 def ( = {}, &block) @_message_rendered = true render_email(@_message.email, , &block) if @_message.email () @_message.() @_message end |