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

EasyCaptcha module

Defined Under Namespace

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

Constant Summary collapse

DEFAULT_CONFIG =
{
  cache: false,
  cache_expire: nil,
  cache_temp_dir: nil,
  cache_size: 500,
  captcha_character_pool: %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],
  captcha_character_count: 6,
  captcha_character_count_max: 6,
  captcha_character_count_min: 6,
  captcha_image_height: 40,
  captcha_image_width: 140
}.freeze
VERSION =
'0.11.0'

Class Method Summary collapse

Class Method Details

.cache?Boolean

:nodoc:

Returns:

  • (Boolean)


62
63
64
# File 'lib/easy_captcha.rb', line 62

def cache? #:nodoc:
  cache
end

.captcha_code_lengthObject



66
67
68
69
70
71
# File 'lib/easy_captcha.rb', line 66

def captcha_code_length
  max = [captcha_character_count_min, captcha_character_count_max].max
  min = [captcha_character_count_min, captcha_character_count_max].min
  return (min..max).to_a.sample if captcha_character_count == :range
  captcha_character_count
end

.espeak(&block) ⇒ Object



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

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

.espeak=(state) ⇒ Object



79
80
81
# File 'lib/easy_captcha.rb', line 79

def espeak=(state)
  @espeak = state.is_a?(TrueClass) ? Espeak.new : false
end

.espeak?Boolean

Returns:

  • (Boolean)


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

def espeak?
  !espeak.is_a?(FalseClass)
end

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

select generator and configure this



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

def generator(generator = nil, &block)
  resolve_generator(generator, &block) unless generator.nil?
  @generator
end

.initObject



92
93
94
95
96
97
98
99
100
# File 'lib/easy_captcha.rb', line 92

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

  # set default generator
  generator :default
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



55
56
57
58
59
60
# File 'lib/easy_captcha.rb', line 55

def setup
  DEFAULT_CONFIG.map do |k, v|
    send("#{k}=", v) if respond_to? "#{k}=".to_sym
  end
  yield self if block_given?
end