Module: EasyCaptcha

Defined in:
lib/easy_captcha.rb,
lib/easy_captcha/espeak.rb,
lib/easy_captcha/captcha.rb,
lib/easy_captcha/version.rb,
lib/easy_captcha/generator.rb,
lib/easy_captcha/view_helpers.rb,
lib/easy_captcha/model_helpers.rb,
lib/easy_captcha/generator/base.rb,
lib/easy_captcha/generator/default.rb,
lib/easy_captcha/captcha_controller.rb,
lib/easy_captcha/controller_helpers.rb,
lib/generators/easy_captcha/install_generator.rb

Overview

Captcha-Plugin for Rails

Defined Under Namespace

Modules: ControllerHelpers, Generator, Generators, ModelHelpers, ViewHelpers Classes: Captcha, CaptchaController, Espeak

Constant Summary collapse

VERSION =
'0.6.5'
@@cache =
false
@@cache_temp_dir =
nil
@@cache_size =
500
@@cache_expire =
nil
@@chars =
%w(2 3 4 5 6 7 9 A C D E F G H J K L M N P Q R S T U X Y Z)
@@length =
6
@@image_width =
140
@@image_height =
40

Class Method Summary collapse

Class Method Details

.cache?Boolean

:nodoc:

Returns:

  • (Boolean)


52
53
54
# File 'lib/easy_captcha.rb', line 52

def cache? #:nodoc:
  cache
end

.espeak(&block) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/easy_captcha.rb', line 80

def espeak(&block)
  if block_given?
    @espeak = Espeak.new &block
  else
    @espeak ||= false
  end
end

.espeak=(state) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/easy_captcha.rb', line 72

def espeak=(state)
  if state === true
    @espeak = Espeak.new
  else
    @espeak = false
  end
end

.espeak?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/easy_captcha.rb', line 88

def espeak?
  not espeak === false
end

.generator(generator = nil, &block) ⇒ Object

select generator and configure this



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/easy_captcha.rb', line 57

def generator(generator = nil, &block)
  if generator.nil?
    @generator
  else
    generator = generator.to_s if generator.is_a? Symbol

    if generator.is_a? String
      generator.gsub!(/^[a-z]|\s+[a-z]/) { |a| a.upcase }
      generator = "EasyCaptcha::Generator::#{generator}".constantize
    end

    @generator = generator.new &block
  end
end

.initObject

called by rails after initialize



115
116
117
118
119
120
121
122
123
124
# File 'lib/easy_captcha.rb', line 115

def init
  require 'easy_captcha/routes'
  ActiveRecord::Base.send :include, ModelHelpers
  ActionController::Base.send :include, ControllerHelpers
  ActionView::Base.send :include, ViewHelpers

  # set default generator
  generator :default

end

.method_missing(name, *args) ⇒ Object

depracated



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/easy_captcha.rb', line 93

def method_missing name, *args
  name = name.to_s # fix for jruby
  depracations = [
      :font_size, :font_fill_color, :font_family, :font_stroke, :font_stroke_color,
      :image_background_color, :sketch, :sketch_radius, :sketch_sigma, :wave,
      :wave_length, :wave_amplitude, :implode, :blur, :blur_radius, :blur_sigma
  ]

  if depracations.include? name[0..-2].to_sym or depracations.include? name.to_sym
    ActiveSupport::Deprecation.warn "EasyCaptcha.#{name} is deprecated."
    if name[-1,1] == '='
      self.generator.send(name, args.first)
    else
      self.generator.send(name)
    end
  else
    super
  end
end

.setup {|_self| ... } ⇒ Object

to configure easy_captcha for a sample look the readme.rdoc file

Yields:

  • (_self)

Yield Parameters:

  • _self (EasyCaptcha)

    the object that the method was called on



48
49
50
# File 'lib/easy_captcha.rb', line 48

def setup
  yield self
end