Module: SimpleCaptchaReloaded::Model

Defined in:
lib/simple_captcha_reloaded/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#captchaObject

Returns the value of attribute captcha.



3
4
5
# File 'lib/simple_captcha_reloaded/model.rb', line 3

def captcha
  @captcha
end

#captcha_keyObject

Returns the value of attribute captcha_key.



2
3
4
# File 'lib/simple_captcha_reloaded/model.rb', line 2

def captcha_key
  @captcha_key
end

Instance Method Details

#captcha_valid?Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/simple_captcha_reloaded/model.rb', line 12

def captcha_valid?
  if @last_result.nil?
    @last_result = begin
                     data = SimpleCaptchaReloaded::Data.where(key: captcha_key).first
                     if !data
                       errors.add :captcha, I18n.t('simple_captcha_reloaded.errors.missing_captcha')
                       false
                     elsif !captcha.present?
                       errors.add :captcha, I18n.t('simple_captcha_reloaded.errors.blank')
                       false
                     elsif not data.valid_captcha?(captcha)
                       errors.add :captcha, I18n.t('simple_captcha_reloaded.errors.wrong')
                       false
                     else
                       true
                     end
                   end
  end
  @last_result
end

#save_with_captcha(*args) ⇒ Object



8
9
10
# File 'lib/simple_captcha_reloaded/model.rb', line 8

def save_with_captcha(*args)
  valid_with_captcha? & save(*args)
end

#valid_with_captcha?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/simple_captcha_reloaded/model.rb', line 4

def valid_with_captcha?
  valid? & captcha_valid?
end