class DbMailerRails::Base
Attributes
object[RW]
Public Instance Methods
build(object = nil, **_args)
click to toggle source
# File lib/db_mailer_rails/base.rb, line 9 def build(object = nil, **_args) self.object = object replacer = Replacer.new(fields_with_data) finder = TemplateFinder.new(self.class) template = finder.db_mail_template mail_params = { from: replacer.replace(template.from), to: replacer.replace(template.to), subject: replacer.replace(template.subject) } # add attachments to mail mail_attachments mail(mail_params) do |format| format.html { render html: replacer.replace(template.body).html_safe, layout: layout_by_environment } end end
fields()
click to toggle source
# File lib/db_mailer_rails/base.rb, line 29 def fields {} end
mail_attachments()
click to toggle source
# File lib/db_mailer_rails/base.rb, line 33 def mail_attachments end
Private Instance Methods
add_inline_image(file_path)
click to toggle source
# File lib/db_mailer_rails/base.rb, line 38 def add_inline_image(file_path) file = file_path.split('/').last image_path = Rails.root.join('app', 'assets', 'images', file_path) attachments.inline[file] = File.read(image_path) if File.exists?(image_path) end
fields_with_data()
click to toggle source
# File lib/db_mailer_rails/base.rb, line 52 def fields_with_data @fields_with_data ||= fields.keys.each_with_object({}) do |field_name, res| res[field_name] = self.send(field_name) end end
layout()
click to toggle source
# File lib/db_mailer_rails/base.rb, line 44 def layout 'mailer' end
layout_by_environment()
click to toggle source
# File lib/db_mailer_rails/base.rb, line 48 def layout_by_environment Rails.env.test? ? false : layout end