Module: HasEmails::Extensions::ActionMailer::InstanceMethods

Defined in:
lib/has_emails/extensions/action_mailer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:


54
55
56
57
58
59
60
# File 'lib/has_emails/extensions/action_mailer.rb', line 54

def self.included(base) #:nodoc:
  base.class_eval do
    alias_method_chain :initialize_defaults, :subject_prefix
    alias_method_chain :subject, :prefix
    alias_method :subject=, :subject_with_prefix
  end
end

Instance Method Details

#email(email) ⇒ Object

Delivers an email based on the content in the specified email


79
80
81
82
83
84
85
86
87
# File 'lib/has_emails/extensions/action_mailer.rb', line 79

def email(email)
  @from       = email.sender.with_name
  @recipients = email.to.map(&:with_name)
  @cc         = email.cc.map(&:with_name)
  @bcc        = email.bcc.map(&:with_name)
  @subject    = email.subject || ''
  @body       = email.body || ''
  @sent_on    = email.updated_at
end

#initialize_defaults_with_subject_prefix(method_name) ⇒ Object

Sets the default subject prefix


73
74
75
76
# File 'lib/has_emails/extensions/action_mailer.rb', line 73

def initialize_defaults_with_subject_prefix(method_name) #:nodoc
  initialize_defaults_without_subject_prefix(method_name)
  @subject_prefix ||= ::ActionMailer::Base.default_subject_prefix.dup
end

#queueObject

Queues the current e-mail that has been constructed


90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/has_emails/extensions/action_mailer.rb', line 90

def queue
  Email.transaction do
    # Create the main email
    email = EmailAddress.find_or_create_by_address(from).emails.build(
      :subject => subject,
      :body => body,
      :to => email_addresses_for(:recipients),
      :cc => email_addresses_for(:cc),
      :bcc => email_addresses_for(:bcc)
    )
    email.queue!
  end
end

#subject_with_prefix(*parameters) ⇒ Object

Sets or gets the subject of the email. All subjects are prefixed with a value indicating the application it is coming from.


64
65
66
67
68
69
70
# File 'lib/has_emails/extensions/action_mailer.rb', line 64

def subject_with_prefix(*parameters)
  if parameters.empty?
    subject_without_prefix
  else
    subject_without_prefix(subject_prefix + subject_without_prefix(*parameters))
  end
end