Class: Smailer::Models::FinishedMail

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/smailer/models/finished_mail.rb

Defined Under Namespace

Classes: Statuses

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add(queued_mail, status = Statuses::SENT, update_sent_mails_count = true) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/smailer/models/finished_mail.rb', line 32

def self.add(queued_mail, status = Statuses::SENT, update_sent_mails_count = true)
  finished = self.new

  fields_to_copy = [:mail_campaign_id, :key, :from, :to, :subject, :retries, :last_retry_at, :last_error]
  fields_to_copy += [:body_html, :body_text] if Smailer::Models::Property.get_boolean('finished_mails.preserve_body')

  fields_to_copy.each do |field|
    finished.send("#{field}=", queued_mail.send(field))
  end

  finished.status = status
  finished.sent_at = Time.now if status == Statuses::SENT

  finished.save!
  queued_mail.destroy
  queued_mail.delete

  if update_sent_mails_count && finished.mail_campaign
    finished.mail_campaign.sent_mails_count += 1
    Compatibility.save_without_validation finished.mail_campaign
  end

  finished
end

Instance Method Details

#opened!Object



27
28
29
30
# File 'lib/smailer/models/finished_mail.rb', line 27

def opened!
  self.opened = true
  Compatibility.save_without_validation self if changed?
end

#status_textObject



20
21
22
23
24
25
# File 'lib/smailer/models/finished_mail.rb', line 20

def status_text
  Statuses.constants.each do |constant_name|
    return constant_name if Statuses.const_get(constant_name) == status
  end
  nil
end