Module: ActsAsTextcaptcha::Textcaptcha::InstanceMethods

Defined in:
lib/acts_as_textcaptcha/textcaptcha.rb

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) perform_textcaptcha?

override this method to toggle textcaptcha checking by default this will only allow new records to be protected with textcaptchas



44
45
46
# File 'lib/acts_as_textcaptcha/textcaptcha.rb', line 44

def perform_textcaptcha?
  !respond_to?('new_record?') || new_record?
end

- (Object) textcaptcha

generate and assign textcaptcha



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/acts_as_textcaptcha/textcaptcha.rb', line 49

def textcaptcha
  if perform_textcaptcha? && textcaptcha_config
    question = answers = nil

    # get textcaptcha from api
    if textcaptcha_config[:api_key]
      question, answers = TextcaptchaApi.fetch(textcaptcha_config[:api_key], textcaptcha_config)
    end

    # fall back to config based textcaptcha
    unless question && answers
      question, answers = textcaptcha_config_questions
    end

    if question && answers
      assign_textcaptcha(question, answers)
    end
  end
end