aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/routing/route_set.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2008-12-07 03:05:03 +0100
committerPratik Naik <pratiknaik@gmail.com>2008-12-07 03:05:03 +0100
commit8f1c229571b4db8dda144bf6eaa193799309e817 (patch)
tree592710207a614428d5cb809f6e13c8b546b58969 /actionpack/lib/action_controller/routing/route_set.rb
parent601e40e744f44fe8819be100a8c472ea161d13ab (diff)
parent9eca588bdfbb41f6b48477025d1cd8eea4a38296 (diff)
downloadrails-8f1c229571b4db8dda144bf6eaa193799309e817.tar.gz
rails-8f1c229571b4db8dda144bf6eaa193799309e817.tar.bz2
rails-8f1c229571b4db8dda144bf6eaa193799309e817.zip
Merge commit 'mainstream/master'
Conflicts: actionmailer/lib/action_mailer/base.rb actionpack/lib/action_controller/base.rb actionpack/lib/action_controller/mime_type.rb railties/doc/guides/html/activerecord_validations_callbacks.html railties/doc/guides/html/caching_with_rails.html railties/doc/guides/html/command_line.html railties/doc/guides/html/configuring.html railties/doc/guides/html/creating_plugins.html railties/doc/guides/html/finders.html railties/doc/guides/html/routing_outside_in.html railties/doc/guides/source/activerecord_validations_callbacks.txt railties/doc/guides/source/caching_with_rails.txt railties/doc/guides/source/command_line.txt railties/doc/guides/source/creating_plugins/acts_as_yaffle.txt railties/doc/guides/source/creating_plugins/controllers.txt railties/doc/guides/source/creating_plugins/core_ext.txt railties/doc/guides/source/creating_plugins/helpers.txt railties/doc/guides/source/creating_plugins/index.txt railties/doc/guides/source/creating_plugins/migration_generator.txt railties/doc/guides/source/creating_plugins/models.txt railties/doc/guides/source/creating_plugins/odds_and_ends.txt railties/doc/guides/source/creating_plugins/routes.txt railties/doc/guides/source/finders.txt railties/doc/guides/source/routing_outside_in.txt railties/doc/guides/source/testing_rails_applications.txt
Diffstat (limited to 'actionpack/lib/action_controller/routing/route_set.rb')
-rw-r--r--actionpack/lib/action_controller/routing/route_set.rb75
1 files changed, 60 insertions, 15 deletions
diff --git a/actionpack/lib/action_controller/routing/route_set.rb b/actionpack/lib/action_controller/routing/route_set.rb
index ff448490e9..13646aef61 100644
--- a/actionpack/lib/action_controller/routing/route_set.rb
+++ b/actionpack/lib/action_controller/routing/route_set.rb
@@ -7,6 +7,8 @@ module ActionController
# Mapper instances have relatively few instance methods, in order to avoid
# clashes with named routes.
class Mapper #:doc:
+ include ActionController::Resources
+
def initialize(set) #:nodoc:
@set = set
end
@@ -136,9 +138,13 @@ module ActionController
end
end
+ def named_helper_module_eval(code, *args)
+ @module.module_eval(code, *args)
+ end
+
def define_hash_access(route, name, kind, options)
selector = hash_access_name(name, kind)
- @module.module_eval <<-end_eval # We use module_eval to avoid leaks
+ named_helper_module_eval <<-end_eval # We use module_eval to avoid leaks
def #{selector}(options = nil)
options ? #{options.inspect}.merge(options) : #{options.inspect}
end
@@ -166,8 +172,9 @@ module ActionController
#
# foo_url(bar, baz, bang, :sort_by => 'baz')
#
- @module.module_eval <<-end_eval # We use module_eval to avoid leaks
+ named_helper_module_eval <<-end_eval # We use module_eval to avoid leaks
def #{selector}(*args)
+
#{generate_optimisation_block(route, kind)}
opts = if args.empty? || Hash === args.first
@@ -182,6 +189,14 @@ module ActionController
end
url_for(#{hash_access_method}(opts))
+
+ end
+ #Add an alias to support the now deprecated formatted_* URL.
+ def formatted_#{selector}(*args)
+ ActiveSupport::Deprecation.warn(
+ "formatted_#{selector}() has been deprecated. please pass format to the standard" +
+ "#{selector}() method instead.", caller)
+ #{selector}(*args)
end
protected :#{selector}
end_eval
@@ -189,9 +204,11 @@ module ActionController
end
end
- attr_accessor :routes, :named_routes, :configuration_file
+ attr_accessor :routes, :named_routes, :configuration_files
def initialize
+ self.configuration_files = []
+
self.routes = []
self.named_routes = NamedRouteCollection.new
@@ -205,7 +222,6 @@ module ActionController
end
def draw
- clear!
yield Mapper.new(self)
install_helpers
end
@@ -229,8 +245,22 @@ module ActionController
routes.empty?
end
+ def add_configuration_file(path)
+ self.configuration_files << path
+ end
+
+ # Deprecated accessor
+ def configuration_file=(path)
+ add_configuration_file(path)
+ end
+
+ # Deprecated accessor
+ def configuration_file
+ configuration_files
+ end
+
def load!
- Routing.use_controllers! nil # Clear the controller cache so we may discover new ones
+ Routing.use_controllers!(nil) # Clear the controller cache so we may discover new ones
clear!
load_routes!
end
@@ -239,24 +269,39 @@ module ActionController
alias reload! load!
def reload
- if @routes_last_modified && configuration_file
- mtime = File.stat(configuration_file).mtime
- # if it hasn't been changed, then just return
- return if mtime == @routes_last_modified
- # if it has changed then record the new time and fall to the load! below
- @routes_last_modified = mtime
+ if configuration_files.any? && @routes_last_modified
+ if routes_changed_at == @routes_last_modified
+ return # routes didn't change, don't reload
+ else
+ @routes_last_modified = routes_changed_at
+ end
end
+
load!
end
def load_routes!
- if configuration_file
- load configuration_file
- @routes_last_modified = File.stat(configuration_file).mtime
+ if configuration_files.any?
+ configuration_files.each { |config| load(config) }
+ @routes_last_modified = routes_changed_at
else
add_route ":controller/:action/:id"
end
end
+
+ def routes_changed_at
+ routes_changed_at = nil
+
+ configuration_files.each do |config|
+ config_changed_at = File.stat(config).mtime
+
+ if routes_changed_at.nil? || config_changed_at > routes_changed_at
+ routes_changed_at = config_changed_at
+ end
+ end
+
+ routes_changed_at
+ end
def add_route(path, options = {})
route = builder.build(path, options)
@@ -358,7 +403,7 @@ module ActionController
end
# don't use the recalled keys when determining which routes to check
- routes = routes_by_controller[controller][action][options.keys.sort_by { |x| x.object_id }]
+ routes = routes_by_controller[controller][action][options.reject {|k,v| !v}.keys.sort_by { |x| x.object_id }]
routes.each do |route|
results = route.__send__(method, options, merged, expire_on)