rucaptcha 0.4.5 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d19351a61db05ab5f038cca14190d70473117a8
4
- data.tar.gz: 17f368f3e963f2bc89597ea6489c61eb1013be94
3
+ metadata.gz: 0c8619ffa153f60752223f1f764b7145849b1b4b
4
+ data.tar.gz: f7d6b3358ba52b86886550e41902cee4220bec28
5
5
  SHA512:
6
- metadata.gz: 1c92ef1378ecfba89ec2aca42e88336690cc23a8e24dde0e0dfeadfe9e9f60e9fd389f3921c3167f3f014b5dbbce9a0e1058a6d39c582ea36a2fc8b37767f1b9
7
- data.tar.gz: b4f5acca22355975f074cc20d0ec6822c4960b8103993b9524e79ae2c4e696c83b34e755189d803a2ab6b91a0384e9840b234ae7f454a5b32223ca998afcb6cf
6
+ metadata.gz: aa2eebcabe01dca90464094dbd7bc367d09c7ab230c2f80a60acada970df844821affeb074ddfba828240576c7b9aa22ed6aed504a4144ce066ef2103580f301
7
+ data.tar.gz: 1f8a4758678ff5b44a94572db65ab6eb7040f451254b58dddeeddc8aa8e4b380805cbd27b994f8fa78f8fad0fb68ba74bb60b8b30ea65869d93bf0a808697915
@@ -1,8 +1,14 @@
1
+ 0.5.0
2
+
3
+ - Fix cache with Rails 5.
4
+
1
5
  0.4.5
6
+ -----
2
7
 
3
8
  - Removed `posix-spawn` dependency, used open3 instead (core funciontality), JRuby compatible (#24)
4
9
 
5
10
  0.4.4
11
+ -----
6
12
 
7
13
  - Remove deprecated `width`, `height` config.
8
14
  - Delete session key after verify (#23).
@@ -25,11 +25,6 @@ module RuCaptcha
25
25
 
26
26
  def configure(&block)
27
27
  config.instance_exec(&block)
28
-
29
- # enable cache if cache_limit less than 1
30
- if config.cache_limit >= 1
31
- RuCaptcha::Captcha.send(:include, RuCaptcha::Cache)
32
- end
33
28
  end
34
29
  end
35
30
  end
@@ -3,30 +3,27 @@ require 'fileutils'
3
3
  module RuCaptcha
4
4
  # File Cache
5
5
  module Cache
6
- extend ActiveSupport::Concern
7
-
8
- included do
9
- class << self
10
- alias_method_chain :create, :cache
11
- alias_method_chain :random_chars, :cache
6
+ def self.prepended(base)
7
+ class << base
8
+ prepend ClassMethods
12
9
  end
13
10
  end
14
11
 
15
12
  module ClassMethods
16
- def create_with_cache(code)
17
- cache.fetch(code) do
18
- create_without_cache(code)
13
+ def create(code)
14
+ cache.fetch(code, expires_in: 1.days) do
15
+ super(code)
19
16
  end
20
17
  end
21
18
 
22
- def random_chars_with_cache
19
+ def random_chars
23
20
  if cached_codes.length >= RuCaptcha.config.cache_limit
24
21
  return cached_codes.sample
25
- else
26
- code = random_chars_without_cache
27
- cached_codes << code
28
- return code
29
22
  end
23
+
24
+ code = super
25
+ cached_codes << code
26
+ code
30
27
  end
31
28
 
32
29
  def cache
@@ -35,7 +32,8 @@ module RuCaptcha
35
32
  cache_path = Rails.root.join('tmp', 'cache', 'rucaptcha')
36
33
  FileUtils.mkdir_p(cache_path) unless File.exist? cache_path
37
34
  @cache = ActiveSupport::Cache::FileStore.new(cache_path)
38
- @cache.clear
35
+ # clear expired captcha cache files on Process restart
36
+ @cache.cleanup
39
37
  @cache
40
38
  end
41
39
 
@@ -77,7 +77,7 @@ module RuCaptcha
77
77
  png_file_path
78
78
  else
79
79
  command.strip!
80
- out, err, st = Open3.capture3(command)
80
+ out, err, _st = Open3.capture3(command)
81
81
  raise "RuCaptcha: #{err.strip}" if err.present?
82
82
  out
83
83
  end
@@ -1,5 +1,12 @@
1
1
  module RuCaptcha
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace RuCaptcha
4
+
5
+ initializer 'rucaptcha.prepend.cache' do
6
+ # enable cache if cache_limit less than 1
7
+ if RuCaptcha.config.cache_limit >= 1
8
+ RuCaptcha::Captcha.send(:prepend, RuCaptcha::Cache)
9
+ end
10
+ end
4
11
  end
5
12
  end
@@ -1,3 +1,3 @@
1
1
  module RuCaptcha
2
- VERSION = '0.4.5'
2
+ VERSION = '0.5.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rucaptcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee
@@ -9,49 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2016-05-25 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rake
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rails
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: 3.3.0
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: 3.3.0
12
+ dependencies: []
55
13
  description:
56
14
  email: huacnlee@gmail.com
57
15
  executables: []