Add custom score and last_activity method to determine if safe or not

master
Guillaume DOTT 2013-01-04 09:59:51 +01:00
parent 475b749cf6
commit 6571e9bef5
2 changed files with 11 additions and 3 deletions

View File

@ -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

View File

@ -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?