rucaptcha/lib/rucaptcha.rb

45 lines
1.0 KiB
Ruby
Raw Normal View History

2015-10-26 13:55:46 +00:00
require 'rails'
require 'action_controller'
require 'active_support/all'
2017-02-09 09:40:39 +00:00
require 'rucaptcha/rucaptcha'
require 'rucaptcha/version'
require 'rucaptcha/configuration'
require 'rucaptcha/controller_helpers'
require 'rucaptcha/view_helpers'
require 'rucaptcha/cache'
require 'rucaptcha/engine'
2015-10-26 06:09:39 +00:00
module RuCaptcha
class << self
def config
return @config if defined?(@config)
@config = Configuration.new
@config.style = :colorful
@config.expires_in = 2.minutes
2016-10-29 03:06:10 +00:00
if Rails.application
@config.cache_store = Rails.application.config.cache_store
else
@config.cache_store = :null_store
end
2015-10-26 06:09:39 +00:00
@config
end
def configure(&block)
config.instance_exec(&block)
end
def generate()
style = config.style == :colorful ? 1 : 0
self.create(style)
end
2015-10-26 06:09:39 +00:00
end
end
ActiveSupport.on_load(:action_controller) do
ActionController::Base.send :include, RuCaptcha::ControllerHelpers
end
2017-02-15 04:31:25 +00:00
ActiveSupport.on_load(:action_view) do
include RuCaptcha::ViewHelpers
end