diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2008-11-26 15:57:36 +0100 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-11-26 15:57:36 +0100 |
commit | 40b40c487040d9c721d486e8ec8cfbc53a8cd79a (patch) | |
tree | 942716155ba5aec22e70daff47498e4c3a7302c5 /actionpack/lib/action_controller/routing/route_set.rb | |
parent | 63d8f56774dcb1ea601928c3eb6c119d359fae10 (diff) | |
download | rails-40b40c487040d9c721d486e8ec8cfbc53a8cd79a.tar.gz rails-40b40c487040d9c721d486e8ec8cfbc53a8cd79a.tar.bz2 rails-40b40c487040d9c721d486e8ec8cfbc53a8cd79a.zip |
Added support for multiple routes files and made draw not clear the map so they can be additive
Diffstat (limited to 'actionpack/lib/action_controller/routing/route_set.rb')
-rw-r--r-- | actionpack/lib/action_controller/routing/route_set.rb | 54 |
1 files changed, 42 insertions, 12 deletions
diff --git a/actionpack/lib/action_controller/routing/route_set.rb b/actionpack/lib/action_controller/routing/route_set.rb index 89cdf9d0f5..a9690d1807 100644 --- a/actionpack/lib/action_controller/routing/route_set.rb +++ b/actionpack/lib/action_controller/routing/route_set.rb @@ -200,9 +200,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 @@ -216,7 +218,6 @@ module ActionController end def draw - clear! yield Mapper.new(self) install_helpers end @@ -240,8 +241,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 @@ -250,24 +265,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) |