Sha256: 61b75be2a05bcdeff7232b85c96018120beba8b97e76583e74564b0d1709dc7a

Contents?: true

Size: 899 Bytes

Versions: 11

Compression:

Stored size: 899 Bytes

Contents

class QueuedDispatch < ActiveRecord::Base
  # Relationships
  belongs_to :dispatch
  belongs_to :subscriber
  
  # Scopes
  scope :queued, -> { where('sent_at IS NULL') }
  scope :sent, -> { where("sent_at IS NOT NULL") }
  scope :failed, -> { where("failed_attempts > ?", 0) }
  scope :opened, -> { where("opened_at IS NOT NULL") }

  # open up everything for mass assignment
  attr_protected
  
  # Action Methods
  def send!
    DispatchMailer.dispatch(self.dispatch, self.subscriber.email, self.subscriber.name, self.subscriber.id).deliver
    self.sent_at = Time.now
    self.save
  end
  handle_asynchronously :send!
  
  def self.send_queued!
    self.queued.all.each { |m| m.send! }
  end
  
  def mark_as_opened!
    self.opened_at = Time.now and self.save
  end
  
  # Query Methods
  def sent?
    self.sent_at
  end
  
  def failed?
    self.failed_attempts > 0 && !self.sent?
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
forge-cli-0.1.10 lib/forge/app/models/queued_dispatch.rb
forge-cli-0.1.9 lib/forge/app/models/queued_dispatch.rb
forge-cli-0.1.8 lib/forge/app/models/queued_dispatch.rb
forge-cli-0.1.7 lib/forge/app/models/queued_dispatch.rb
forge-cli-0.1.6 lib/forge/app/models/queued_dispatch.rb
forge-cli-0.1.5 lib/forge/app/models/queued_dispatch.rb
forge-cli-0.1.4 lib/forge/app/models/queued_dispatch.rb
forge-cli-0.1.3 lib/forge/app/models/queued_dispatch.rb
forge-cli-0.1.2 lib/forge/app/models/queued_dispatch.rb
forge-cli-0.1.1 lib/forge/app/models/queued_dispatch.rb
forge-cli-0.1.0 lib/forge/app/models/queued_dispatch.rb