module Splam

Attributes

skip_splam_check[RW]
splam_reasons[R]
splam_score[R]

Public Class Methods

included(base) click to toggle source
# File lib/splam.rb, line 48
def self.included(base)
  # Autoload all files in rules
  # This is bad, mkay
  Dir["#{File.dirname(__FILE__)}/splam/rules/*.rb"].each do |f|
    require f
  end
  require "splam/ngram"
  base.send :extend, ClassMethods
end

Public Instance Methods

splam?() click to toggle source
# File lib/splam.rb, line 102
def splam?
  # run_splam_suite # ask yourself, do you want this to be cached for each record instance or not?
  self.class.splam_suite.splam?(splam_score)
end
validates_as_spam() click to toggle source
# File lib/splam.rb, line 107
def validates_as_spam
  errors.add(self.class.splam_suite.body, "looks like spam.") if (!skip_splam_check? && splam?)
end

Protected Instance Methods

run_splam_suite(attr_suffix = nil) click to toggle source
# File lib/splam.rb, line 112
def run_splam_suite(attr_suffix = nil)
  splam_suite = self.class.splam_suite || raise("Splam::Suite is not initialized")
  return false if (splam_suite.conditions && !splam_suite.conditions.call(self)) || 
                  skip_splam_check ||
                  send(splam_suite.body).nil?
  @request = splam_suite.request.call(self) if splam_suite.request
  @splam_score, @splam_reasons = splam_suite.run(self, @request)
  instance_variable_get("@splam_#{attr_suffix}") if attr_suffix
end
skip_splam_check?() click to toggle source
# File lib/splam.rb, line 122
def skip_splam_check?
  # This enables us to use a checkbox
  skip_splam_check.to_i > 0
end