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:



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 = build_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.default_message_options = default_message_options.merge(value).freeze if value
  default_message_options
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

#attachmentsObject



102
103
104
105
106
# File 'lib/outbox/notifier.rb', line 102

def attachments
  # Make sure the email message instance exists
  email({}) if email.nil?
  email.attachments
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

#messageObject

The composed Outbox::Message instance.



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

def message
  render_message unless message_rendered?
  @_message
end

#message_rendered?Boolean

Returns true if the message has already been rendered.

Returns:

  • (Boolean)


77
78
79
# File 'lib/outbox/notifier.rb', line 77

def message_rendered?
  @_message_rendered
end

#process(*args) ⇒ Object

:nodoc:



63
64
65
66
67
68
# File 'lib/outbox/notifier.rb', line 63

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.



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

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