class Captchah::Generators::Captcha
Constants
- DEFAULT_ACTION_LABEL
- DEFAULT_DIFFICULTY
- DEFAULT_EXPIRY
- DEFAULT_PUZZLE_FONT
- DEFAULT_RELOAD_COUNT
- DEFAULT_RELOAD_LABEL
- DEFAULT_RELOAD_MAX
- DEFAULT_WIDTH
Attributes
action_label[R]
css[R]
difficulty[R]
expiry[R]
id[R]
puzzle_font[R]
reload[R]
reload_count[R]
reload_label[R]
reload_max[R]
width[R]
Public Class Methods
call(*args)
click to toggle source
# File lib/captchah/generators/captcha.rb, line 15 def self.call(*args) new(*args).send(:call) end
new(args = {})
click to toggle source
# File lib/captchah/generators/captcha.rb, line 19 def initialize(args = {}) @id = args[:id] || SecureRandom.uuid @difficulty = args[:difficulty] || DEFAULT_DIFFICULTY @expiry = args[:expiry] || DEFAULT_EXPIRY @width = (args[:width] || DEFAULT_WIDTH).to_i @action_label = args[:action_label] || DEFAULT_ACTION_LABEL @reload_label = args[:reload_label] || DEFAULT_RELOAD_LABEL @reload_max = args[:reload_max] || DEFAULT_RELOAD_MAX @reload_count = args[:reload_count] || DEFAULT_RELOAD_COUNT @reload = args[:reload] == false ? false : allow_reload? @css = (args[:css] != false) @puzzle_font = args[:puzzle_font] || DEFAULT_PUZZLE_FONT end
Private Instance Methods
allow_reload?()
click to toggle source
# File lib/captchah/generators/captcha.rb, line 95 def allow_reload? @reload_count <= @reload_max end
arguments_check()
click to toggle source
# File lib/captchah/generators/captcha.rb, line 99 def arguments_check unless difficulty.is_a?(Integer) && difficulty.between?(1, 5) raise Error, "'difficulty' must be an Integer value between 1 and 5." end return if expiry.is_a?(ActiveSupport::Duration) raise Error, "'expiry' must be an ActiveSupport::Duration object." end
call()
click to toggle source
# File lib/captchah/generators/captcha.rb, line 49 def call arguments_check Html.call( id: id, puzzle: puzzle, width: width, action_label: action_label, truth_payload: truth_payload, reload_payload: reload_payload, reload_label: reload_label, reload: reload, css: css ) end
puzzle()
click to toggle source
# File lib/captchah/generators/captcha.rb, line 65 def puzzle Puzzle.call(truth, difficulty, puzzle_font) end
reload_payload()
click to toggle source
# File lib/captchah/generators/captcha.rb, line 77 def reload_payload return unless reload Encryptor.encrypt( id: id, difficulty: difficulty, expiry: expiry, width: width, action_label: action_label, reload_label: reload_label, reload_max: reload_max, reload_count: reload_count, reload: reload, css: css, puzzle_font: puzzle_font ) end
truth()
click to toggle source
# File lib/captchah/generators/captcha.rb, line 69 def truth @truth ||= Truth.call(difficulty) end
truth_payload()
click to toggle source
# File lib/captchah/generators/captcha.rb, line 73 def truth_payload Encryptor.encrypt(truth: truth, timestamp: Time.current + expiry) end