Sha256: aa1942d134d9e2430ad80e47494707bbf91ea6712fe9f833b87f01199fd70ef9

Contents?: true

Size: 735 Bytes

Versions: 4

Compression:

Stored size: 735 Bytes

Contents

module DeliveryUncle
  class Activity < ActiveRecord::Base 
    scope :not_expired, -> { where("expired is null or expired = 0")}
    scope :with_object_type, ->(object_type) { where(object_type: object_type) }
    scope :with_verb, ->(verb) { where(verb: verb) }
    
    validates_presence_of :actor, :verb, :object_type
    after_create :expire_blocked_mailers
    
    def expire_blocked_mailers
      case verb
      when :unblock_mailer
        self.class.with_verb(:block_mailer).with_object_type(object_type).each do |activity|
          activity.expired = true
          activity.save
        end
      end
    end

    def self.blocked_mailers
      not_expired.with_verb(:block_mailer).map(&:object_type)
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
delivery_uncle-0.1.5 app/models/delivery_uncle/activity.rb
delivery_uncle-0.1.4 app/models/delivery_uncle/activity.rb
delivery_uncle-0.1.3 app/models/delivery_uncle/activity.rb
delivery_uncle-0.1.2 app/models/delivery_uncle/activity.rb