require 'rails'
require 'action_controller'
require 'active_support/all'
require 'rucaptcha/rucaptcha'
require 'rucaptcha/version'
require 'rucaptcha/configuration'
require 'rucaptcha/controller_helpers'
require 'rucaptcha/view_helpers'
require 'rucaptcha/cache'
require 'rucaptcha/engine'

module RuCaptcha
  class << self
    def config
      return @config if defined?(@config)
      @config = Configuration.new
      @config.style       = :colorful
      @config.expires_in  = 2.minutes
      if Rails.application
        @config.cache_store = Rails.application.config.cache_store
      else
        @config.cache_store = :null_store
      end
      @config
    end

    def configure(&block)
      config.instance_exec(&block)
    end

    def generate()
      style = config.style == :colorful ? 1 : 0
      self.create(style)
    end
  end
end

ActionController::Base.send(:include, RuCaptcha::ControllerHelpers)
ActionView::Base.send(:include, RuCaptcha::ViewHelpers)

require 'rails'
require 'action_controller'
require 'active_support/all'
require 'rucaptcha/rucaptcha'
require 'rucaptcha/version'
require 'rucaptcha/configuration'
require 'rucaptcha/controller_helpers'
require 'rucaptcha/view_helpers'
require 'rucaptcha/cache'
require 'rucaptcha/engine'

module RuCaptcha
  class << self
    def config
      return @config if defined?(@config)
      @config = Configuration.new
      @config.style       = :colorful
      @config.expires_in  = 2.minutes
      if Rails.application
        @config.cache_store = Rails.application.config.cache_store
      else
        @config.cache_store = :null_store
      end
      @config
    end

    def configure(&block)
      config.instance_exec(&block)
    end

    def generate()
      style = config.style == :colorful ? 1 : 0
      self.create(style)
    end
  end
end

ActiveSupport.on_load(:action_controller) do
  ActionController::Base.send :include, RuCaptcha::ControllerHelpers
end

ActiveSupport.on_load(:active_view) do
  include RuCaptcha::ViewHelpers
end

Use `ActiveSupport.on_load` to extend ActionController and ActionView.
Use `ActiveSupport.on_load` to extend ActionController and ActionView.

http://api.rubyonrails.org/classes/ActiveSupport/LazyLoadHooks.html
https://github.com/rails/rails/blob/92703a9ea5d8b96f30e0b706b801c9185ef14f0e/actionpack/lib/action_controller/base.rb#L264
https://github.com/rails/rails/blob/7da8d76206271bdf200ea201f7e5a49afb9bc9e7/actionview/lib/action_view/base.rb#L215
