Module: RedisCaptcha::Model

Extended by:
ActiveSupport::Concern
Defined in:
lib/redis_captcha/model.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
# File 'lib/redis_captcha/model.rb', line 5

def self.included(base)
  base.extend(ClassMethods)
  base.send :validate, :check_captcha
  base.send :after_save, :delete_captcha
  base.send :attr_accessor, :captcha, :captcha_key
end

Instance Method Details

#check_captchaObject



19
20
21
22
23
24
25
# File 'lib/redis_captcha/model.rb', line 19

def check_captcha
  if without_captcha?
    @skip_captcha = false
  else
    errors.add(:captcha, RedisCaptcha::options[:error_message]) unless key_handler.valid?(captcha)
  end
end

#delete_captchaObject



27
28
29
# File 'lib/redis_captcha/model.rb', line 27

def delete_captcha
  key_handler.delete
end

#key_handlerObject



15
16
17
# File 'lib/redis_captcha/model.rb', line 15

def key_handler
  @key_handler ||= RedisCaptcha::KeyHandler.new(captcha_key)
end

#save_without_captchaObject



40
41
42
43
# File 'lib/redis_captcha/model.rb', line 40

def save_without_captcha
  @skip_captcha = true
  self.save
end

#valid_without_captcha?Boolean

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/redis_captcha/model.rb', line 35

def valid_without_captcha?
  @skip_captcha = true
  self.valid?
end

#without_captcha?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/redis_captcha/model.rb', line 31

def without_captcha?
  !!@skip_captcha
end