- Mount Router by default, not need config now.

- Default use [:file_store, 'tmp/cache/rucaptcha/session'] as RuCaptcha.config.cache_store, now it can work without any configurations.
- Improve README doc.
This commit is contained in:
Jason Lee committed 2017-03-08 11:54:36 +08:00
1 parent afc6b47ff1
commit bb5b4efb8a
3 files changed
+50 -33

No files matched your search

+23 -1
View File
@@ -19,8 +19,9 @@ module RuCaptcha
if Rails.application
@config.cache_store = Rails.application.config.cache_store
else
@config.cache_store = :null_store
@config.cache_store = :mem_cache_store
end
@config.cache_store
@config
end
@@ -32,6 +33,27 @@ module RuCaptcha
style = config.style == :colorful ? 1 : 0
self.create(style)
end
def check_cache_store!
cache_store = RuCaptcha.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)
RuCaptcha.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/initializes/rucaptcha.rb` to setup `cache_store`.
More infomation please read GitHub RuCaptcha README file.
https://github.com/huacnlee/rucaptcha
"
end
end
end
end
+7 -19
View File
@@ -2,26 +2,14 @@ module RuCaptcha
class Engine < ::Rails::Engine
isolate_namespace RuCaptcha
initializer 'rucaptcha.prepend.cache' do
cache_store = RuCaptcha.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)
msg = "
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 :#{store_name}.
Please make config file `config/initializes/rucaptcha.rb` to setup `cache_store`.
More infomation please read GitHub RuCaptcha README file.
"
if store_name == :null_store
raise msg
else
puts msg
end
initializer 'rucaptcha.init' do |app|
# https://github.com/rails/rails/blob/3-2-stable/actionpack/lib/action_dispatch/routing/route_set.rb#L268
# `app.routes.append` start from Rails 3.2 - 5.0
app.routes.append do
mount RuCaptcha::Engine => '/rucaptcha'
end
RuCaptcha.check_cache_store!
end
end
end