Module: HoneypotCaptcha::SpamProtection

Defined in:
lib/honeypot-captcha.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/honeypot-captcha.rb', line 21

def self.included(base) # :nodoc:
  base.send :helper_method, :honeypot_fields
  base.send :helper_method, :honeypot_string
  base.send :helper_method, :honeypot_style_class

  if base.respond_to? :before_action
    base.send :prepend_before_action, :protect_from_spam, :only => [:create, :update]
  elsif base.respond_to? :before_filter
    base.send :prepend_before_filter, :protect_from_spam, :only => [:create, :update]
  end
end

Instance Method Details

#honeypot_fieldsObject



5
6
7
# File 'lib/honeypot-captcha.rb', line 5

def honeypot_fields
  { :a_comment_body => 'Do not fill in this field' }
end

#honeypot_stringObject



9
10
11
# File 'lib/honeypot-captcha.rb', line 9

def honeypot_string
  'hp'
end

#honeypot_style_classObject



13
14
15
# File 'lib/honeypot-captcha.rb', line 13

def honeypot_style_class
  nil
end

#protect_from_spamObject



17
18
19
# File 'lib/honeypot-captcha.rb', line 17

def protect_from_spam
  head :ok if honeypot_fields.any? { |f,l| !params[f].blank? }
end