public
Fork of rails/rails
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/nullstyle/rails.git
add support for specifying a routes file in rails config
nullstyle (author)
Thu May 01 01:52:20 -0700 2008
commit  94b6d861507932cbc93eb2b7311d1f17fa451767
tree    36ba796ba22c41c924f3d91ed9889d55f255f016
parent  6f20efdaf733db26fbf337da73121983785064d5
...
189
190
191
192
 
193
194
195
...
238
239
240
241
242
 
 
243
244
245
...
249
250
251
252
253
254
 
 
 
255
256
257
...
189
190
191
 
192
193
194
195
...
238
239
240
 
 
241
242
243
244
245
...
249
250
251
 
 
 
252
253
254
255
256
257
0
@@ -189,7 +189,7 @@ module ActionController
0
           end
0
       end
0
 
0
- attr_accessor :routes, :named_routes
0
+ attr_accessor :routes, :named_routes, :configuration_file
0
 
0
       def initialize
0
         self.routes = []
0
@@ -238,8 +238,8 @@ module ActionController
0
       alias reload! load!
0
 
0
       def reload
0
- if @routes_last_modified && defined?(RAILS_ROOT)
0
- mtime = File.stat("#{RAILS_ROOT}/config/routes.rb").mtime
0
+ if @routes_last_modified && configuration_file
0
+ mtime = File.stat(configuration_file).mtime
0
           # if it hasn't been changed, then just return
0
           return if mtime == @routes_last_modified
0
           # if it has changed then record the new time and fall to the load! below
0
@@ -249,9 +249,9 @@ module ActionController
0
       end
0
 
0
       def load_routes!
0
- if defined?(RAILS_ROOT) && defined?(::ActionController::Routing::Routes) && self == ::ActionController::Routing::Routes
0
- load File.join("#{RAILS_ROOT}/config/routes.rb")
0
- @routes_last_modified = File.stat("#{RAILS_ROOT}/config/routes.rb").mtime
0
+ if configuration_file
0
+ load configuration_file
0
+ @routes_last_modified = File.stat(configuration_file).mtime
0
         else
0
           add_route ":controller/:action/:id"
0
         end
...
2341
2342
2343
 
2344
2345
2346
2347
2348
 
2349
2350
2351
...
2386
2387
2388
 
 
 
 
 
 
 
 
2389
2390
2391
...
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
...
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
0
@@ -2341,11 +2341,13 @@ uses_mocha 'route loading' do
0
     def setup
0
       routes.instance_variable_set '@routes_last_modified', nil
0
       silence_warnings { Object.const_set :RAILS_ROOT, '.' }
0
+ ActionController::Routing::Routes.configuration_file = File.join(RAILS_ROOT, 'config', 'routes.rb')
0
 
0
       @stat = stub_everything
0
     end
0
 
0
     def teardown
0
+ ActionController::Routing::Routes.configuration_file = nil
0
       Object.send :remove_const, :RAILS_ROOT
0
     end
0
 
0
@@ -2386,6 +2388,14 @@ uses_mocha 'route loading' do
0
 
0
       Inflector.inflections { |inflect| inflect.uncountable('equipment') }
0
     end
0
+
0
+ def test_load_with_configuration
0
+ routes.configuration_file = "foobarbaz"
0
+ File.expects(:stat).returns(@stat)
0
+ routes.expects(:load).with("foobarbaz")
0
+
0
+ routes.reload
0
+ end
0
 
0
     private
0
     def routes
...
382
383
384
 
385
386
387
...
499
500
501
 
 
 
 
502
503
504
...
631
632
633
 
634
635
636
...
771
772
773
 
 
 
 
774
775
776
...
382
383
384
385
386
387
388
...
500
501
502
503
504
505
506
507
508
509
...
636
637
638
639
640
641
642
...
777
778
779
780
781
782
783
784
785
786
0
@@ -382,6 +382,7 @@ module Rails
0
     def initialize_routing
0
       return unless configuration.frameworks.include?(:action_controller)
0
       ActionController::Routing.controller_paths = configuration.controller_paths
0
+ ActionController::Routing::Routes.configuration_file = configuration.routes_configuration_file
0
       ActionController::Routing::Routes.reload
0
     end
0
 
0
@@ -499,6 +500,10 @@ module Rails
0
     # The path to the database configuration file to use. (Defaults to
0
     # <tt>config/database.yml</tt>.)
0
     attr_accessor :database_configuration_file
0
+
0
+ # The path to the routes configuration file to use. (Defaults to
0
+ # <tt>config/routes.rb</tt>.)
0
+ attr_accessor :routes_configuration_file
0
 
0
     # The list of rails framework components that should be loaded. (Defaults
0
     # to <tt>:active_record</tt>, <tt>:action_controller</tt>,
0
@@ -631,6 +636,7 @@ module Rails
0
       self.plugin_locators = default_plugin_locators
0
       self.plugin_loader = default_plugin_loader
0
       self.database_configuration_file = default_database_configuration_file
0
+ self.routes_configuration_file = default_routes_configuration_file
0
       self.gems = default_gems
0
 
0
       for framework in default_frameworks
0
@@ -771,6 +777,10 @@ module Rails
0
         File.join(root_path, 'config', 'database.yml')
0
       end
0
 
0
+ def default_routes_configuration_file
0
+ File.join(root_path, 'config', 'routes.rb')
0
+ end
0
+
0
       def default_view_path
0
         File.join(root_path, 'app', 'views')
0
       end

Comments

    No one has commented yet.