From c4a4032b6b42f6da1143452e4cce06649ce39ef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 12 Jun 2010 20:48:37 +0200 Subject: [PATCH] Use ActiveSupport::Dependencies.ref to abstract constant lookup logic. --- lib/devise/mapping.rb | 12 +++++------- lib/devise/rails/routes.rb | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/devise/mapping.rb b/lib/devise/mapping.rb index e5573829..a0a1e077 100644 --- a/lib/devise/mapping.rb +++ b/lib/devise/mapping.rb @@ -22,7 +22,7 @@ module Devise # # is the modules included in the class # class Mapping #:nodoc: - attr_reader :singular, :plural, :path, :controllers, :path_names, :path_prefix, :klass + attr_reader :singular, :plural, :path, :controllers, :path_names, :path_prefix, :class_name alias :name :singular # Loop through all mappings looking for a map that matches with the requested @@ -63,9 +63,11 @@ module Devise @plural = name.to_sym @path = (options.delete(:path) || name).to_sym - @klass = (options.delete(:class_name) || name.to_s.classify).to_s @singular = (options.delete(:singular) || name.to_s.singularize).to_sym + @class_name = (options.delete(:class_name) || name.to_s.classify).to_s + @ref = ActiveSupport::Dependencies.ref(@class_name) + @path_prefix = "/#{options.delete(:path_prefix)}/".squeeze("/") @controllers = Hash.new { |h,k| h[k] = "devise/#{k}" } @@ -82,12 +84,8 @@ module Devise end # Gives the class the mapping points to. - # Reload mapped class each time when cache_classes is false. def to - return @to if @to - klass = @klass.constantize - @to = klass if Rails.configuration.cache_classes - klass + @ref.get end def strategies diff --git a/lib/devise/rails/routes.rb b/lib/devise/rails/routes.rb index 4b483990..52cc1fcd 100644 --- a/lib/devise/rails/routes.rb +++ b/lib/devise/rails/routes.rb @@ -92,10 +92,10 @@ module ActionDispatch::Routing mapping = Devise.add_model(resource, options) begin - raise_no_devise_method_error!(mapping.klass) unless mapping.to.respond_to?(:devise) + raise_no_devise_method_error!(mapping.class_name) unless mapping.to.respond_to?(:devise) rescue NoMethodError => e raise unless e.message.include?("undefined method `devise'") - raise_no_devise_method_error!(mapping.klass) + raise_no_devise_method_error!(mapping.class_name) end routes = mapping.routes