Class: Captcher::BaseCaptcha

Inherits:
Object
  • Object
show all
Defined in:
lib/captcher/base_captcha.rb

Direct Known Subclasses

Captchas::CodeCaptcha

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

.nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/captcher/base_captcha.rb', line 6

def name
  @name
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



18
19
20
# File 'lib/captcher/base_captcha.rb', line 18

def config
  @config
end

#payloadObject

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_initializeObject



27
# File 'lib/captcher/base_captcha.rb', line 27

def after_initialize; end

#own_configObject



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

Raises:

  • (NotImplementedError)


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

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/captcher/base_captcha.rb', line 42

def validate(confirmation)
  raise NotImplementedError
end