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,16 +230,17 @@ module Devise
# A method used internally to setup warden manager from the Rails initialize # A method used internally to setup warden manager from the Rails initialize
# block. # block.
def self.configure_warden! #:nodoc: 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
warden_config.failure_app = Devise::FailureApp Devise.mappings.each_value do |mapping|
warden_config.default_scope = Devise.default_scope warden_config.scope_defaults mapping.name, :strategies => mapping.strategies
end
Devise.mappings.each_value do |mapping| @@warden_config_block.try :call, Devise.warden_config
warden_config.scope_defaults mapping.name, :strategies => mapping.strategies true
end end
@@warden_config_block.try :call, Devise.warden_config
end end
# Generate a friendly string randomically to be used as token. # Generate a friendly string randomically to be used as token.

View file

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

View file

@ -1,32 +1,32 @@
require 'devise/rails/routes' require 'devise/rails/routes'
require 'devise/rails/warden_compat' 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 module Devise
class Engine < ::Rails::Engine class Engine < ::Rails::Engine
config.devise = Devise config.devise = Devise
initializer "devise.ensure_routes_are_loaded", :before => :load_app_classes, :after => :load_config_initializers do |app| config.app_middleware.use Warden::Manager do |config|
app.reload_routes! Devise.warden_config = config
end end
initializer "devise.add_middleware" do |app| # Force routes to be loaded if we are doing any eager load.
app.config.middleware.use Warden::Manager do |config| config.before_eager_load { |app| app.reload_routes! }
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
config.after_initialize do config.after_initialize do
I18n.available_locales
flash = [:unauthenticated, :unconfirmed, :invalid, :invalid_token, :timeout, :inactive, :locked] 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 [] keys = flash & (translations[:devise][:sessions].keys) rescue []
if keys.any? if keys.any?

View file

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