Module: BlogsCaptcha
- Defined in:
- lib/blogs_captcha.rb,
lib/blogs_captcha/cache.rb,
lib/blogs_captcha/engine.rb,
lib/blogs_captcha/version.rb,
lib/blogs_captcha/configuration.rb,
lib/blogs_captcha/controller_helpers.rb,
ext/blogs_captcha/blogs_captcha.c
Defined Under Namespace
Modules: ControllerHelpers
Classes: Configuration, Engine
Constant Summary
collapse
- VERSION =
'0.1.0'
Class Method Summary
collapse
Class Method Details
.cache ⇒ Object
5
6
7
8
9
|
# File 'lib/blogs_captcha/cache.rb', line 5
def cache
return @cache if defined? @cache
@cache = ActiveSupport::Cache.lookup_store(BlogsCaptcha.config.cache_store)
@cache
end
|
.check_cache_store! ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/blogs_captcha.rb', line 51
def check_cache_store!
cache_store = BlogsCaptcha.config.cache_store
store_name = cache_store.is_a?(Array) ? cache_store.first : cache_store
if [:memory_store, :null_store, :file_store].include?(store_name)
BlogsCaptcha.config.cache_store = [:file_store, Rails.root.join('tmp/cache/rucaptcha/session')]
puts "
RuCaptcha's cache_store requirements are stored across processes and machines,
such as :mem_cache_store, :redis_store, or other distributed storage.
But your current set is #{cache_store}, it has changed to :file_store for working.
NOTE: :file_store is still not a good way, it only works with single server case.
Please make config file `config/initializers/rucaptcha.rb` to setup `cache_store`.
More infomation please read GitHub RuCaptcha README file.
https://github.com/huacnlee/rucaptcha
"
end
end
|
.config ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/blogs_captcha.rb', line 15
def config
return @config if defined?(@config)
@config = Configuration.new
@config.style = :colorful
@config.length = 5
@config.strikethrough = true
@config.outline = false
@config.expires_in = 2.minutes
@config.skip_cache_store_check = false
if Rails.application
@config.cache_store = Rails.application.config.cache_store
else
@config.cache_store = :mem_cache_store
end
@config.cache_store
@config
end
|
34
35
36
|
# File 'lib/blogs_captcha.rb', line 34
def configure(&block)
config.instance_exec(&block)
end
|
.create ⇒ Object
215
|
# File 'ext/blogs_captcha/blogs_captcha.c', line 215
VALUE create(VALUE self, VALUE style, VALUE length, VALUE line, VALUE filter);
|
.generate ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/blogs_captcha.rb', line 38
def generate()
style = config.style == :colorful ? 1 : 0
length = config.length
unless length.in?(3..7)
raise BlogsCaptcha::Errors::Configuration, 'length config error, value must in 3..7'
end
strikethrough = config.strikethrough ? 1 : 0
outline = config.outline ? 1 : 0
self.create(style, length, strikethrough, outline)
end
|