From 6571e9bef5385b96de7e6efc040b64a31604a4d3 Mon Sep 17 00:00:00 2001 From: Guillaume DOTT Date: Fri, 4 Jan 2013 09:59:51 +0100 Subject: [PATCH] Add custom score and last_activity method to determine if safe or not --- lib/project-honeypot.rb | 2 +- lib/project_honeypot/url.rb | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/project-honeypot.rb b/lib/project-honeypot.rb index 175d943..aa862a1 100644 --- a/lib/project-honeypot.rb +++ b/lib/project-honeypot.rb @@ -6,7 +6,7 @@ require "project_honeypot/rack/forbidden" module ProjectHoneypot class << self - attr_accessor :api_key + attr_accessor :api_key, :score, :last_activity def api_key raise "ProjectHoneypot really needs its api_key set to work" unless @api_key diff --git a/lib/project_honeypot/url.rb b/lib/project_honeypot/url.rb index 9dee9e3..ce45d34 100644 --- a/lib/project_honeypot/url.rb +++ b/lib/project_honeypot/url.rb @@ -7,8 +7,16 @@ module ProjectHoneypot process_score(honeypot_response) end - def safe? - @safe + def safe?(hash = {}) + score = hash[:score] || ProjectHoneypot.score + last_activity = hash[:last_activity] || ProjectHoneypot.last_activity + + @safe || + !( + last_activity.nil? && score.nil? || + !score.nil? && self.score > score || + !last_activity.nil? && self.last_activity > last_activity + ) end def comment_spammer?