Class: Outbox::Notifier

Inherits:
ActionMailer::Base
  • Object
show all
Defined in:
lib/outbox/notifier.rb

Class Method Summary collapse

Instance Method Summary collapse

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

#messageObject

The composed Outbox::Message instance.



47
48
49
50
# File 'lib/outbox/notifier.rb', line 47

def message
  render_message unless message_rendered?
  @_message
end

#message_rendered?Boolean

Returns true if the message has already been rendered.

Returns:

  • (Boolean)


53
54
55
# File 'lib/outbox/notifier.rb', line 53

def message_rendered?
  @_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 render_message(options = {}, &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.
  email_options = options.extract! :content_type, :charset, :parts_order,
                                   :body, :template_name, :template_path
  email_options.merge!(options.delete(:email)) if options[:email]
  email_options[:subject] ||= email.subject
  email = render_email(email_options, &block)

  @_message.assign_message_type_values(options)
  assign_body_from_email(email)
  @_message
end