Sha256: 3db14922df83cce113485ae2f7c65b70a37a7bb768110e85acc50d490d47d01c

Contents?: true

Size: 699 Bytes

Versions: 11

Compression:

Stored size: 699 Bytes

Contents

module Cms
  class EmailMessage < ActiveRecord::Base

    include DefaultAccessible

    scope :undelivered, :conditions => "delivered_at is null"
    validates_presence_of :recipients
    after_create :deliver_now

    def delivered?
      !!delivered_at
    end

    def self.deliver!
      # Send all messages, 100 at a time
      undelivered.all(:limit => 100).each do |m|
        m.deliver!
      end
    end

    #TODO: Take this out when we have an email queue processor
    def deliver_now
      deliver!
    end

    def deliver!
      return false if delivered?
      Cms::EmailMessageMailer.email_message(self).deliver
      update_attributes(:delivered_at => Time.now)
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
browsercms-3.5.7 app/models/cms/email_message.rb
browsercms-3.5.6 app/models/cms/email_message.rb
browsercms-3.5.5 app/models/cms/email_message.rb
browsercms-3.5.4 app/models/cms/email_message.rb
browsercms-3.5.3 app/models/cms/email_message.rb
browsercms-3.5.2 app/models/cms/email_message.rb
browsercms-3.5.1 app/models/cms/email_message.rb
browsercms-3.5.0 app/models/cms/email_message.rb
browsercms-3.5.0.rc3 app/models/cms/email_message.rb
browsercms-3.5.0.rc2 app/models/cms/email_message.rb
browsercms-3.5.0.rc1 app/models/cms/email_message.rb