Sha256: e44a0d5a3623fbed306516ca65d3d20531610c07224eaef7e1bf96170899e9db

Contents?: true

Size: 885 Bytes

Versions: 19

Compression:

Stored size: 885 Bytes

Contents

class Trigger < ActiveRecord::Base
  belongs_to :pending_item, :polymorphic => true

  class << self
    def post_action(due_at, item, method='came_due')
      create!(:due_at => due_at, :pending_item => item,
              :trigger_method => method)
      fire
    end

    def fire
      destroy_all ['due_at <= ?', Time.now]
      true
    end

    def remove(pending_item, conditions = { })
      return if pending_item.new_record?
      conditions_string =
        conditions.keys.collect{ |k| "(#{k} = :#{k})"}.join(' AND ')
      with_scope(:find => { :conditions => [conditions_string, conditions]}) do
        delete_all(["pending_item_id = ? AND pending_item_type = ?",
                    pending_item.id, pending_item.class.to_s])
      end
    end
  end

  def before_destroy
    returning true do
      pending_item.send(trigger_method) if pending_item
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
typo-5.5 app/models/trigger.rb
typo-5.4.4 app/models/trigger.rb
typo-5.4.3 app/models/trigger.rb
typo-5.4.2 app/models/trigger.rb
typo-5.4.1 app/models/trigger.rb
typo-5.4 app/models/trigger.rb
typo-5.0.1 app/models/trigger.rb
typo-5.0.2 app/models/trigger.rb
typo-5.0.3.98.1 app/models/trigger.rb
typo-5.0 app/models/trigger.rb
typo-5.0.3.98 app/models/trigger.rb
typo-5.1.1 app/models/trigger.rb
typo-5.1.2 app/models/trigger.rb
typo-5.1.3 app/models/trigger.rb
typo-5.1.98 app/models/trigger.rb
typo-5.1 app/models/trigger.rb
typo-5.2.98 app/models/trigger.rb
typo-5.2 app/models/trigger.rb
typo-5.3 app/models/trigger.rb