Module: ActsAsTextcaptcha::Textcaptcha

Defined in:
lib/acts_as_textcaptcha/textcaptcha.rb

Overview

:nodoc:

Defined Under Namespace

Modules: InstanceMethods

Instance Method Summary (collapse)

Instance Method Details

- (Object) acts_as_textcaptcha(options = nil)



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/acts_as_textcaptcha/textcaptcha.rb', line 11

def acts_as_textcaptcha(options = nil)
  cattr_accessor :textcaptcha_config
  attr_accessor  :textcaptcha_question, :textcaptcha_answer, :textcaptcha_key

  if respond_to?(:accessible_attributes)
    if accessible_attributes.nil? && respond_to?(:attr_protected)
      attr_protected :textcaptcha_question
    elsif respond_to?(:attr_accessible)
      attr_accessible :textcaptcha_answer, :textcaptcha_key
    end
  end

  validate :validate_textcaptcha, :if => :perform_textcaptcha?

  if options.is_a?(Hash)
    self.textcaptcha_config = options.symbolize_keys!
  else
    begin
      self.textcaptcha_config = YAML.load(File.read("#{Rails.root ? Rails.root.to_s : '.'}/config/textcaptcha.yml"))[Rails.env].symbolize_keys!
    rescue
      raise 'could not find any textcaptcha options, in config/textcaptcha.yml or model - run rake textcaptcha:config to generate a template config file'
    end
  end

  include InstanceMethods
end