Sha256: 9d639a55ff4e7fd3efc85e6a8546262b8752745dc698b40239dc5cd763f7e256

Contents?: true

Size: 673 Bytes

Versions: 70

Compression:

Stored size: 673 Bytes

Contents

# If you want to use this module, you need to add a boolean field
# 'marked_as_spam' to the model.
module Concerns
  module Spammable
    extend ActiveSupport::Concern

    included do
      scope :spam, ->{ where(marked_as_spam: true) }
      scope :not_spam, -> { where('marked_as_spam = 0 OR marked_as_spam IS NULL') }

      after_initialize :spam_defaults
    end

    def mark_as_spam!
      update_attribute :marked_as_spam, true
    end

    def unmark_as_spam!
      update_attribute :marked_as_spam, false
    end

    private

    def spam_defaults
      if self.new_record?
        self.marked_as_spam = false if marked_as_spam.nil?
      end
    end
  end
end

Version data entries

70 entries across 70 versions & 1 rubygems

Version Path
udongo-7.9.0 app/models/concerns/spammable.rb
udongo-7.8.1 app/models/concerns/spammable.rb
udongo-7.8.0 app/models/concerns/spammable.rb
udongo-7.7.2 app/models/concerns/spammable.rb
udongo-7.7.1 app/models/concerns/spammable.rb
udongo-7.7.0 app/models/concerns/spammable.rb
udongo-7.6.2 app/models/concerns/spammable.rb
udongo-7.6.1 app/models/concerns/spammable.rb
udongo-7.6.0 app/models/concerns/spammable.rb
udongo-7.5.1 app/models/concerns/spammable.rb
udongo-7.5.0 app/models/concerns/spammable.rb
udongo-7.4.2 app/models/concerns/spammable.rb
udongo-7.4.1 app/models/concerns/spammable.rb
udongo-7.4.0 app/models/concerns/spammable.rb
udongo-7.3.5 app/models/concerns/spammable.rb
udongo-7.3.4 app/models/concerns/spammable.rb
udongo-7.3.3 app/models/concerns/spammable.rb
udongo-7.3.2 app/models/concerns/spammable.rb
udongo-7.3.1 app/models/concerns/spammable.rb
udongo-7.2.1 app/models/concerns/spammable.rb