Class: Outbox::Notifier
- Inherits:
-
ActionMailer::Base
- Object
- ActionMailer::Base
- Outbox::Notifier
- Defined in:
- lib/outbox/notifier.rb
Class Method Summary collapse
-
.notifier_name(value = nil) ⇒ Object
(also: notifier_name=)
Returns the name of current notifier.
Instance Method Summary collapse
-
#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.
-
#render_message(options = {}, &block) ⇒ Object
Renders the message body.
Constructor Details
#initialize(method_name = nil, *args) ⇒ Notifier
:nodoc:
37 38 39 40 41 42 43 44 |
# File 'lib/outbox/notifier.rb', line 37 def initialize(method_name = nil, *args) # :nodoc: super() # Make sure we don't ever get a NullMail object. @_mail_was_called = true @_message_rendered = false @_message = Outbox::Message.new self.class.default_params.dup process(method_name, *args) if method_name end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (protected)
93 94 95 96 97 98 99 |
# File 'lib/outbox/notifier.rb', line 93 def method_missing(method, *args, &block) if @_message.respond_to?(method) @_message.public_send(method, *args, &block) else super end end |
Class Method Details
.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.
17 18 19 20 21 22 23 |
# File 'lib/outbox/notifier.rb', line 17 def notifier_name(value = nil) if value.nil? self.mailer_name else self.mailer_name = value end end |
Instance Method Details
#message ⇒ Object
The composed Outbox::Message instance.
47 48 49 50 |
# File 'lib/outbox/notifier.rb', line 47 def unless @_message end |
#message_rendered? ⇒ Boolean
Returns true if the message has already been rendered.
53 54 55 |
# File 'lib/outbox/notifier.rb', line 53 def @_message_rendered 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.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/outbox/notifier.rb', line 60 def ( = {}, &block) @_message_rendered = true # Render an email using the #mail interface so we don't have # to rewrite the template logic. Even if we aren't sending an email # we can still use the rendered templates in other messages types. = .extract! :content_type, :charset, :parts_order, :body, :template_name, :template_path .merge!(.delete(:email)) if [:email] [:subject] ||= email.subject email = render_email(, &block) @_message.() assign_body_from_email(email) @_message end |