1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Clean up the whole loading mess and closes #247. This commit depends on latest Rails.

This commit is contained in:
José Valim 2010-05-16 00:38:40 +02:00
parent d38421dde8
commit e905762611
4 changed files with 26 additions and 23 deletions

View file

@ -230,8 +230,7 @@ module Devise
# A method used internally to setup warden manager from the Rails initialize
# block.
def self.configure_warden! #:nodoc:
return unless warden_config
@@warden_configured ||= begin
warden_config.failure_app = Devise::FailureApp
warden_config.default_scope = Devise.default_scope
@ -240,6 +239,8 @@ module Devise
end
@@warden_config_block.try :call, Devise.warden_config
true
end
end
# Generate a friendly string randomically to be used as token.

View file

@ -9,6 +9,7 @@ module Devise
include ActionController::RackDelegation
include ActionController::UrlFor
include ActionController::Redirecting
include Rails.application.routes.url_helpers
delegate :flash, :to => :request

View file

@ -1,32 +1,32 @@
require 'devise/rails/routes'
require 'devise/rails/warden_compat'
# Include UrlHelpers in ActionController and ActionView as soon as they are loaded.
ActiveSupport.on_load(:action_controller) { include Devise::Controllers::UrlHelpers }
ActiveSupport.on_load(:action_view) { include Devise::Controllers::UrlHelpers }
module Devise
class Engine < ::Rails::Engine
config.devise = Devise
initializer "devise.ensure_routes_are_loaded", :before => :load_app_classes, :after => :load_config_initializers do |app|
app.reload_routes!
end
initializer "devise.add_middleware" do |app|
app.config.middleware.use Warden::Manager do |config|
config.app_middleware.use Warden::Manager do |config|
Devise.warden_config = config
Devise.configure_warden!
end
end
initializer "devise.add_url_helpers" do |app|
Devise::FailureApp.send :include, app.routes.url_helpers
ActionController::Base.send :include, Devise::Controllers::UrlHelpers
ActionView::Base.send :include, Devise::Controllers::UrlHelpers
end
# Force routes to be loaded if we are doing any eager load.
config.before_eager_load { |app| app.reload_routes! }
config.after_initialize do
I18n.available_locales
flash = [:unauthenticated, :unconfirmed, :invalid, :invalid_token, :timeout, :inactive, :locked]
I18n.backend.send(:translations).each do |locale, translations|
translations = begin
I18n.available_locales
I18n.backend.send(:translations)
rescue Exception => e # Do not care if something fails
{}
end
translations.each do |locale, translations|
keys = flash & (translations[:devise][:sessions].keys) rescue []
if keys.any?

View file

@ -2,6 +2,7 @@ require 'test_helper'
module Devise
def self.yield_and_restore
@@warden_configured = nil
c, b = @@warden_config, @@warden_config_block
yield
ensure