lib/splam.rb in splam-0.1.1 vs lib/splam.rb in splam-0.2.0
- old
+ new
@@ -27,15 +27,15 @@
end
memo
end
end
- def run(record)
+ def run(record, request)
score, reasons = 0, []
rules.each do |rule_class, weight|
weight ||= 1
- worker = rule_class.run(self, record, weight)
+ worker = rule_class.run(self, record, weight, request)
score += worker.score
reasons << worker.reasons
end
[score, reasons]
end
@@ -49,10 +49,11 @@
# 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
module ClassMethods
def splam_suite; @splam_suite; end
@@ -111,10 +112,11 @@
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?
- @splam_score, @splam_reasons = splam_suite.run(self)
+ @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
def skip_splam_check?
# This enables us to use a checkbox
\ No newline at end of file