Class: Outbox::Notifier

Inherits:
ActionMailer::Base
  • Object
show all
Extended by:
DefineInheritableMethod
Includes:
NotifierTypes
Defined in:
lib/outbox/notifier.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_name = nil, *args) ⇒ Notifier

:nodoc:



40
41
42
43
44
45
# File 'lib/outbox/notifier.rb', line 40

def initialize(method_name = nil, *args) # :nodoc:
  super()
  @_message_rendered = false
  @_message = build_message
  process(method_name, *args) if method_name
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.



19
20
21
22
23
24
25
# File 'lib/outbox/notifier.rb', line 19

def notifier_name(value = nil)
  if value.nil?
    mailer_name
  else
    self.mailer_name = value
  end
end

Instance Method Details

#attachmentsObject



86
87
88
89
90
# File 'lib/outbox/notifier.rb', line 86

def attachments
  # Make sure the email message instance exists
  email({}) if email.nil?
  email.attachments
end

#headers(args = nil) ⇒ Object

:nodoc:



76
77
78
79
80
81
82
83
84
# File 'lib/outbox/notifier.rb', line 76

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

#messageObject

The composed Outbox::Message instance.



55
56
57
58
# File 'lib/outbox/notifier.rb', line 55

def message
  render_message unless message_rendered?
  @_message
end

#message_rendered?Boolean

Returns true if the message has already been rendered.

Returns:

  • (Boolean)


61
62
63
# File 'lib/outbox/notifier.rb', line 61

def message_rendered?
  @_message_rendered
end

#process(*args) ⇒ Object

:nodoc:



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

def process(*args) # :nodoc:
  original_message = @_message
  super
  # Make sure we don't ever get a NullMail object.
  @_message = original_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.



68
69
70
71
72
73
74
# File 'lib/outbox/notifier.rb', line 68

def render_message(options = {}, &block)
  @_message_rendered = true
  render_email(@_message.email, options, &block) if @_message.email
  render_message_types(options)
  @_message.assign_message_type_values(options)
  @_message
end