Module: Commentable::Model

Extended by:
ActiveSupport::Concern
Defined in:
lib/commentable/model.rb

Overview

Comment model.

Example:

class Comment < ActiveRecord::Base
  include Commentable::Model

  self.spam_quota  = 5
  self.troll_quota = 10
  self.quota_time  = 1.week
end

Class attributes:

  • spam_quota - how many spams are allowed for a single IP (defaults to 4)

  • troll_quota - how many trolls are allowed for a single IP (defaults to 4)

  • time_quota - since how long should we check for spams and trolls (defauls to 1 day)

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#spam_quotaObject

Adds an error on base if current ip generated too much spams.



32
33
34
# File 'lib/commentable/model.rb', line 32

def spam_quota
  errors[:base] << "spam_quota" if self.class.count_for_user_ip(user_ip, :spam) >= self.class.spam_quota
end

#troll_quotaObject

Adds an error on base if current ip generated too much trolls.



37
38
39
# File 'lib/commentable/model.rb', line 37

def troll_quota
  errors[:base] << "troll_quota" if self.class.count_for_user_ip(user_ip, :troll) >= self.class.troll_quota
end