Class: MailEngine::MailTemplateFile

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/mail_engine/mail_template_file.rb

Overview

Schema Information

Table name: mail_template_files

id               :integer         not null, primary key
mail_template_id :integer
file             :string(255)
size             :integer
created_at       :datetime
updated_at       :datetime

Instance Method Summary collapse

Instance Method Details

#clone(*args) ⇒ Object



39
40
41
42
43
# File 'app/models/mail_engine/mail_template_file.rb', line 39

def clone *args
  file_clone = super *args
  file_clone.file = File.open(self.file.path)
  file_clone
end

#image?Boolean

Returns:

  • (Boolean)


22
23
24
25
# File 'app/models/mail_engine/mail_template_file.rb', line 22

def image?
  return false if attributes["file"].blank?
  File.basename(attributes["file"]) =~ /\.(j(e)?pg)|(png)|(gif)$/i
end

#replace_url_in_mail_templateObject



27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/mail_engine/mail_template_file.rb', line 27

def replace_url_in_mail_template
  if self.file_changed? and self.file_was.present?
    self.mail_template.update_attribute :body,
      MailEngine::HtmlDocumentAssetsReplacer.replace_resource_in_html(
        self.mail_template.body,
        self.file_was,
        File.basename(self.file.url),
        :filename
      )
  end
end