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
- #check_captcha ⇒ Object
- #delete_captcha ⇒ Object
- #key_handler ⇒ Object
- #save_without_captcha ⇒ Object
- #valid_without_captcha? ⇒ Boolean
- #without_captcha? ⇒ Boolean
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_captcha ⇒ Object
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::[:error_message]) unless key_handler.valid?(captcha) end end |
#delete_captcha ⇒ Object
27 28 29 |
# File 'lib/redis_captcha/model.rb', line 27 def delete_captcha key_handler.delete end |
#key_handler ⇒ Object
15 16 17 |
# File 'lib/redis_captcha/model.rb', line 15 def key_handler @key_handler ||= RedisCaptcha::KeyHandler.new(captcha_key) end |
#save_without_captcha ⇒ Object
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
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
31 32 33 |
# File 'lib/redis_captcha/model.rb', line 31 def without_captcha? !!@skip_captcha end |