Class: Captcher::BaseCaptcha
- Inherits:
-
Object
- Object
- Captcher::BaseCaptcha
show all
- Defined in:
- lib/captcher/base_captcha.rb
Constant Summary
collapse
- SESSION_KEY =
"captcha_state".freeze
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ BaseCaptcha
Returns a new instance of BaseCaptcha.
20
21
22
23
24
25
|
# File 'lib/captcher/base_captcha.rb', line 20
def initialize(options = {})
options = options.with_indifferent_access
@config = options[:config] if options[:config]
@payload = options[:payload] if options[:payload]
after_initialize
end
|
Class Attribute Details
.name ⇒ Object
Returns the value of attribute name.
6
7
8
|
# File 'lib/captcher/base_captcha.rb', line 6
def name
@name
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
18
19
20
|
# File 'lib/captcher/base_captcha.rb', line 18
def config
@config
end
|
#payload ⇒ Object
Returns the value of attribute payload.
18
19
20
|
# File 'lib/captcher/base_captcha.rb', line 18
def payload
@payload
end
|
Class Method Details
.restore(session) ⇒ Object
8
9
10
11
|
# File 'lib/captcher/base_captcha.rb', line 8
def restore(session)
state = session[SESSION_KEY]
new(state) if state
end
|
.restore_or_create(config, session) ⇒ Object
13
14
15
|
# File 'lib/captcher/base_captcha.rb', line 13
def restore_or_create(config, session)
restore(session) || new(config: config).store(session)
end
|
Instance Method Details
#after_initialize ⇒ Object
27
|
# File 'lib/captcher/base_captcha.rb', line 27
def after_initialize; end
|
#own_config ⇒ Object
34
35
36
|
# File 'lib/captcher/base_captcha.rb', line 34
def own_config
@own_config ||= @config[self.class.name.to_sym]
end
|
#represent(format = :html, options = {}) ⇒ Object
38
39
40
|
# File 'lib/captcher/base_captcha.rb', line 38
def represent(format = :html, options = {})
raise NotImplementedError
end
|
#store(session) ⇒ Object
29
30
31
32
|
# File 'lib/captcher/base_captcha.rb', line 29
def store(session)
session[SESSION_KEY] = { payload: payload, config: config }
self
end
|
#validate(confirmation) ⇒ Object
42
43
44
|
# File 'lib/captcher/base_captcha.rb', line 42
def validate(confirmation)
raise NotImplementedError
end
|