lib/devise/mapping.rb in devise-1.1.rc2 vs lib/devise/mapping.rb in devise-1.1.0

- old
+ new

@@ -20,23 +20,13 @@ # # mapping.modules #=> [:authenticatable] # # is the modules included in the class # class Mapping #:nodoc: - attr_reader :singular, :plural, :path, :controllers, :path_names, :path_prefix, :class_name + attr_reader :singular, :plural, :path, :controllers, :path_names, :class_name alias :name :singular - # Loop through all mappings looking for a map that matches with the requested - # path (ie /users/sign_in). If a path prefix is given, it's taken into account. - def self.find_by_path(path) - Devise.mappings.each_value do |mapping| - route = path.split("/")[mapping.segment_position] - return mapping if route && mapping.path == route.to_sym - end - nil - end - # Receives an object and find a scope for it. If a scope cannot be found, # raises an error. If a symbol is given, it's considered to be the scope. def self.find_scope!(duck) case duck when String, Symbol @@ -49,35 +39,26 @@ raise "Could not find a valid mapping for #{duck}" end def initialize(name, options) #:nodoc: - if as = options.delete(:as) - ActiveSupport::Deprecation.warn ":as is deprecated, please use :path instead." - options[:path] ||= as - end + @plural = (options[:as] ? "#{options[:as]}_#{name}" : name).to_sym + @singular = (options[:singular] || @plural.to_s.singularize).to_sym - if scope = options.delete(:scope) - ActiveSupport::Deprecation.warn ":scope is deprecated, please use :singular instead." - options[:singular] ||= scope - end - - @plural = name.to_sym - @path = (options.delete(:path) || name).to_sym - @singular = (options.delete(:singular) || name.to_s.singularize).to_sym - - @class_name = (options.delete(:class_name) || name.to_s.classify).to_s + @class_name = (options[:class_name] || name.to_s.classify).to_s @ref = ActiveSupport::Dependencies.ref(@class_name) - @path_prefix = "/#{options.delete(:path_prefix)}/".squeeze("/") + @path = (options[:path] || name).to_s + @path_prefix = options[:path_prefix] - @controllers = Hash.new { |h,k| h[k] = "devise/#{k}" } - @controllers.merge!(options.delete(:controllers) || {}) + mod = options[:module] || "devise" + @controllers = Hash.new { |h,k| h[k] = "#{mod}/#{k}" } + @controllers.merge!(options[:controllers] || {}) - @path_names = Hash.new { |h,k| h[k] = k.to_s } + @path_names = Hash.new { |h,k| h[k] = k.to_s } @path_names.merge!(:registration => "") - @path_names.merge!(options.delete(:path_names) || {}) + @path_names.merge!(options[:path_names] || {}) end # Return modules for the mapping. def modules @modules ||= to.respond_to?(:devise_modules) ? to.devise_modules : [] @@ -94,31 +75,15 @@ def routes @routes ||= ROUTES.values_at(*self.modules).compact.uniq end - # Keep a list of allowed controllers for this mapping. It's useful to ensure - # that an Admin cannot access the registrations controller unless it has - # :registerable in the model. - def allowed_controllers - @allowed_controllers ||= begin - canonical = CONTROLLERS.values_at(*self.modules).compact - @controllers.values_at(*canonical) - end - end - - # Return in which position in the path prefix devise should find the as mapping. - def segment_position - self.path_prefix.count("/") - end - - # Returns the raw path using path_prefix and as. - def full_path - path_prefix + path.to_s - end - def authenticatable? @authenticatable ||= self.modules.any? { |m| m.to_s =~ /authenticatable/ } + end + + def fullpath + "#{@path_prefix}/#{@path}".squeeze("/") end # Create magic predicates for verifying what module is activated by this map. # Example: #