config.line -> config.strikethrough and release version 2.2.0

This commit is contained in:
Jason Lee 2017-12-07 17:04:25 +08:00
parent 3939d1bb02
commit 0561e88a22
8 changed files with 32 additions and 21 deletions

View File

@ -1,3 +1,9 @@
2.2.0
-----
- Add option `config.length` for support change number chars.
- Add option `config.strikethrough` for enable or disable strikethrough.
2.1.3 2.1.3
----- -----

View File

@ -1,7 +1,7 @@
PATH PATH
remote: . remote: .
specs: specs:
rucaptcha (2.1.4) rucaptcha (2.2.0)
railties (>= 3.2) railties (>= 3.2)
GEM GEM
@ -142,4 +142,4 @@ DEPENDENCIES
rucaptcha! rucaptcha!
BUNDLED WITH BUNDLED WITH
1.14.5 1.15.4

View File

@ -20,6 +20,7 @@ This is a Captcha gem for Rails Applications which generates captcha image by C
- High performance. - High performance.
## Usage ## Usage
Put rucaptcha in your `Gemfile`: Put rucaptcha in your `Gemfile`:
``` ```
@ -41,10 +42,10 @@ RuCaptcha.configure do
 # 默认:会从 Rails 配置的 cache_store 里面读取相同的配置信息,并尝试用可以运行的方式,用于存储验证码字符  # 默认:会从 Rails 配置的 cache_store 里面读取相同的配置信息,并尝试用可以运行的方式,用于存储验证码字符
 # 但如果是 [:null_store, :memory_store, :file_store] 之类的,你可以通过下面的配置项单独给 RuCaptcha 配置 cache_store  # 但如果是 [:null_store, :memory_store, :file_store] 之类的,你可以通过下面的配置项单独给 RuCaptcha 配置 cache_store
 self.cache_store = :mem_cache_store  self.cache_store = :mem_cache_store
# 验证码长度 length, 默认是 5, allows: [3,4,5,6,7] # Chars length, default: 5, allows: [3 - 7]
# self.length = 5 # self.length = 5
# 验证码横线 line, 默认显示横线, default: true, allows: [true, false], 设置为false时, 横线不是显示, 验证码识别度高. # enable/disable Strikethrough.
# self.line = true # self.strikethrough = true
end end
``` ```

View File

@ -13,6 +13,6 @@ task default: :spec
task :preview do task :preview do
require 'rucaptcha' require 'rucaptcha'
res = RuCaptcha.create(1) res = RuCaptcha.create(1, 3, 1)
puts res[1] puts res[1]
end end

View File

@ -17,8 +17,9 @@ module RuCaptcha
@config = Configuration.new @config = Configuration.new
@config.style = :colorful @config.style = :colorful
@config.length = 5 @config.length = 5
@config.line = true @config.strikethrough = true
@config.expires_in = 2.minutes @config.expires_in = 2.minutes
if Rails.application if Rails.application
@config.cache_store = Rails.application.config.cache_store @config.cache_store = Rails.application.config.cache_store
else else
@ -35,9 +36,13 @@ module RuCaptcha
def generate() def generate()
style = config.style == :colorful ? 1 : 0 style = config.style == :colorful ? 1 : 0
length = config.length length = config.length
raise Rucaptcha::Errors::Configuration, 'length config error, value must in 3..7' unless length.in?(3..7)
line = config.line ? 1 : 0 unless length.in?(3..7)
self.create(style, length, line) raise Rucaptcha::Errors::Configuration, 'length config error, value must in 3..7'
end
strikethrough = config.strikethrough ? 1 : 0
self.create(style, length, strikethrough)
end end
def check_cache_store! def check_cache_store!

View File

@ -7,10 +7,9 @@ module RuCaptcha
attr_accessor :expires_in attr_accessor :expires_in
# Color style, default: :colorful, allows: [:colorful, :black_white] # Color style, default: :colorful, allows: [:colorful, :black_white]
attr_accessor :style attr_accessor :style
# Captcha Digits: default 5, allows: [3,4,5,6,7] # Chars length: default 5, allows: [3..7]
attr_accessor :length attr_accessor :length
# rucaptcha line, default: true, allows: [true, false] # strikethrough, default: true
attr_accessor :line attr_accessor :strikethrough
end end
end end

View File

@ -1,3 +1,3 @@
module RuCaptcha module RuCaptcha
VERSION = '2.1.4' VERSION = '2.2.0'
end end

View File

@ -82,14 +82,14 @@ describe RuCaptcha do
expect(res[1]).not_to eq(nil) expect(res[1]).not_to eq(nil)
end end
it 'should work with line true' do it 'should work with strikethrough enable' do
res = RuCaptcha.create(1, 7, 1) res = RuCaptcha.create(1, 7, 1)
expect(res.length).to eq(2) expect(res.length).to eq(2)
expect(res[0].length).to eq(7) expect(res[0].length).to eq(7)
expect(res[1]).not_to eq(nil) expect(res[1]).not_to eq(nil)
end end
it 'should work with line false' do it 'should work with strikethrough disable' do
res = RuCaptcha.create(1, 7, 0) res = RuCaptcha.create(1, 7, 0)
expect(res.length).to eq(2) expect(res.length).to eq(2)
expect(res[0].length).to eq(7) expect(res[0].length).to eq(7)