Module: CustomCaptcha::Configuration

Defined in:
lib/custom_captcha/configuration.rb

Class Method Summary collapse

Class Method Details

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



16
17
18
19
20
21
22
# File 'lib/custom_captcha/configuration.rb', line 16

def configure
  yield self
  # make inage files path and defined @@images_path_definite
  make_and_define_images_path()
  # reload all image files key
  CustomCaptcha::Utils.reload_image_files_paths()
end

.default_image_columnsObject

image columns setting



44
45
46
# File 'lib/custom_captcha/configuration.rb', line 44

def default_image_columns
  120
end

.default_image_rowsObject

image rows setting



52
53
54
# File 'lib/custom_captcha/configuration.rb', line 52

def default_image_rows
  40
end

.default_image_styleObject

image style setting



60
61
62
# File 'lib/custom_captcha/configuration.rb', line 60

def default_image_style

end

.default_images_pathObject

images path setting



86
87
88
# File 'lib/custom_captcha/configuration.rb', line 86

def default_images_path
  File.join(Dir::tmpdir, 'captcha_images')
end

.default_text_lengthObject

image text length setting



73
74
75
# File 'lib/custom_captcha/configuration.rb', line 73

def default_text_length
  5
end

.default_text_rangeObject

image text range setting



65
66
67
# File 'lib/custom_captcha/configuration.rb', line 65

def default_text_range
  ('a'..'z').to_a + (0..9).to_a
end

.disable?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/custom_captcha/configuration.rb', line 39

def disable?
  !@@enable
end

.image_columnsObject



47
48
49
# File 'lib/custom_captcha/configuration.rb', line 47

def image_columns
  image_columns = @@image_columns.to_i.blank? ? default_image_columns() : @@image_columns
end

.image_rowsObject



55
56
57
# File 'lib/custom_captcha/configuration.rb', line 55

def image_rows
  image_rows = @@image_rows.to_i.blank? ? default_image_rows() : @@image_rows
end

.images_pathObject



89
90
91
# File 'lib/custom_captcha/configuration.rb', line 89

def images_path
  images_path = @@images_path.to_s.blank? ? default_images_path() : @@images_path
end

.make_and_define_images_pathObject

images path make and define



94
95
96
97
98
99
100
101
102
103
# File 'lib/custom_captcha/configuration.rb', line 94

def make_and_define_images_path
  images_path = images_path()
  begin
    FileUtils.mkdir_p images_path
  rescue
    raise CustomCaptcha::MakeImagePathError
  else
    @@images_path_definite = images_path
  end
end

.reset_configObject Also known as: init_config



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/custom_captcha/configuration.rb', line 24

def reset_config
  configure do |config|
    config.image_columns  = default_image_columns()
    config.image_rows     = default_image_rows()
    config.image_style    = CustomCaptcha::Image.image_style.keys.first
    config.text_range     = default_text_range()
    config.text_length    = default_text_length()
    config.images_path    = default_images_path()
    config.enable         = true
    config.salt           = SecureRandom.hex(10)
  end
  make_and_define_images_path()
end

.text_lengthObject



76
77
78
79
80
81
82
83
# File 'lib/custom_captcha/configuration.rb', line 76

def text_length
  text_length = @@text_length.to_i.blank? ? default_text_length() : @@text_length
  if 4 < text_length or text_length < 10
    text_length
  else
    default_text_length()
  end
end

.text_rangeObject



68
69
70
# File 'lib/custom_captcha/configuration.rb', line 68

def text_range
  text_range = @@text_range.to_a.blank? ? default_text_range() : @@text_range
end