Sha256: c5bbb69ac60df88909954c911671802f1461a482b706774cc8048b9d2fc93fc0
Contents?: true
Size: 1.3 KB
Versions: 1
Compression:
Stored size: 1.3 KB
Contents
module DeliveryUncle class EmailRequest < ActiveRecord::Base scope :order_by_latest, -> { order('created_at DESC') } scope :not_sent, -> { where('status != ?', 'sent') } scope :with_mailer_method, ->(mailer, mailer_method) { where(mailer: mailer, mailer_method: mailer_method) } def self.create(mailer, mailer_method, *args) mail = mailer.send(mailer_method, *args) raise 'mail with attachment is not supported yet' if mail.has_attachments? request = DeliveryUncle::EmailRequest.new request.mail_body = encode_mail(mail) request.mailer = mailer.to_s request.mailer_method = mailer_method request.status = :new request.mail_type = :deliver request.request_from = (caller[1][/`.*'/][1..-2] rescue nil) request end def self.encode_mail(mail) mail.header[:bcc] ? mail.header[:bcc].do_encode('Bcc') << mail.encoded : mail.encoded end def mail @mail ||= ::Mail.new(mail_body) end def paused? status == :paused || status == 'paused' end def sent? status == :sent || status == 'sent' end def save_status!(status) update_attribute(:status,status) end def self.mailers group(:mailer).order('mailer ASC').map(&:mailer) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
delivery_uncle-0.1.5 | app/models/delivery_uncle/email_request.rb |