Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 4762

Show
Ignore:
Timestamp:
08/15/06 01:28:06 (2 years ago)
Author:
ulysses
Message:

Add controller_paths variable to Routing; Assign Routing.controller_paths from initializer; fix script/about and rails info controller.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r4757 r4762  
    11*SVN* 
    22 
     3* Add controller_paths variable to Routing. [Nicholas Seckar] 
     4 
    35* Fix assert_redirected_to issue with named routes for module controllers.  [Rick Olson] 
    46 
    57* Tweak RoutingError message to show option diffs, not just missing named route significant keys. [Rick Olson] 
    68 
     9>>>>>>> .r4761 
    710* Invoke method_missing directly on hidden actions. Closes #3030. [Nicholas Seckar] 
    811 
  • trunk/actionpack/lib/action_controller/routing.rb

    r4756 r4762  
    5050  module Routing 
    5151    SEPARATORS = %w( / ; . , ? ) 
     52 
     53    # The root paths which may contain controller files 
     54    mattr_accessor :controller_paths 
     55    self.controller_paths = [] 
    5256 
    5357    class << self 
     
    5963      end 
    6064 
    61       def normalize_paths(paths = $LOAD_PATH
     65      def normalize_paths(paths
    6266        # do the hokey-pokey of path normalization... 
    6367        paths = paths.collect do |path| 
     
    8185          @possible_controllers = [] 
    8286         
    83           paths = $LOAD_PATH.select { |path| File.directory?(path) && path != "." } 
     87          paths = controller_paths.select { |path| File.directory?(path) && path != "." } 
    8488 
    8589          seen_paths = Hash.new {|h, k| h[k] = true; false} 
     
    8791            Dir["#{load_path}/**/*_controller.rb"].collect do |path| 
    8892              next if seen_paths[path.gsub(%r{^\.[/\\]}, "")] 
    89              
     93               
    9094              controller_name = path[(load_path.length + 1)..-1] 
    91               next unless path_may_be_controller?(controller_name) 
    92  
     95               
    9396              controller_name.gsub!(/_controller\.rb\Z/, '') 
    9497              @possible_controllers << controller_name 
     
    100103        end 
    101104        @possible_controllers 
    102       end 
    103  
    104       def path_may_be_controller?(path) 
    105         path !~ /(?:rails\/.*\/(?:examples|test))|(?:actionpack\/lib\/action_controller.rb$)|(?:app\/controllers)/o 
    106105      end 
    107106 
  • trunk/actionpack/test/controller/routing_test.rb

    r4757 r4762  
    15151515   
    15161516  def test_possible_controllers 
    1517     true_load_paths = $LOAD_PATH.dup 
     1517    true_controller_paths = ActionController::Routing.controller_paths 
    15181518     
    15191519    ActionController::Routing.use_controllers! nil 
    15201520    Object.send(:const_set, :RAILS_ROOT, File.dirname(__FILE__) + '/controller_fixtures') 
    15211521     
    1522     $LOAD_PATH.clear 
    1523     $LOAD_PATH.concat [ 
     1522    ActionController::Routing.controller_paths = [ 
    15241523      RAILS_ROOT, RAILS_ROOT + '/app/controllers', RAILS_ROOT + '/vendor/plugins/bad_plugin/lib' 
    15251524    ] 
     
    15271526    assert_equal ["admin/user", "plugin", "user"], ActionController::Routing.possible_controllers.sort 
    15281527  ensure 
    1529     if true_load_paths 
    1530       $LOAD_PATH.clear 
    1531       $LOAD_PATH.concat true_load_paths 
     1528    if true_controller_paths 
     1529      ActionController::Routing.controller_paths = true_controller_paths 
    15321530    end 
    15331531    Object.send(:remove_const, :RAILS_ROOT) rescue nil 
  • trunk/railties/CHANGELOG

    r4760 r4762  
    11*SVN* 
     2 
     3* Assign Routing.controller_paths; fix script/about and rails info controller. [Nicholas Seckar] 
    24 
    35* Don't warn dispatcher of Reloadable deprecations. [Nicholas Seckar] 
  • trunk/railties/lib/initializer.rb

    r4736 r4762  
    151151    # Add the load paths used by support functions such as the info controller 
    152152    def add_support_load_paths 
    153       builtins = File.join(File.dirname(File.dirname(__FILE__)), 'builtin', '*') 
    154       $LOAD_PATH.concat(Dir[builtins]) 
    155153    end 
    156154 
     
    177175        config = configuration 
    178176        constants = self.class.constants 
    179         eval(IO.read(configuration.environment_path), binding
     177        eval(IO.read(configuration.environment_path), binding, configuration.environment_path
    180178        (self.class.constants - constants).each do |const| 
    181179          Object.const_set(const, self.class.const_get(const)) 
     
    252250    def initialize_routing 
    253251      return unless configuration.frameworks.include?(:action_controller) 
     252      ActionController::Routing.controller_paths = configuration.controller_paths 
    254253      ActionController::Routing::Routes.reload 
    255254    end 
     
    512511    end 
    513512     
     513    def builtin_directories 
     514      # Include builtins only in the development environment. 
     515      (environment == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : [] 
     516    end 
     517     
    514518    private 
    515519      def root_path 
     
    590594         
    591595        paths.concat Dir["#{root_path}/vendor/plugins/*/lib/"] 
     596        paths.concat builtin_directories 
    592597      end 
    593598 
     
    609614       
    610615      def default_controller_paths 
    611         [ File.join(root_path, 'app', 'controllers'), File.join(root_path, 'components'), File.join(RAILTIES_PATH, 'builtin', 'controllers') ] 
     616        paths = [ File.join(root_path, 'app', 'controllers'), File.join(root_path, 'components') ] 
     617        paths.concat builtin_directories 
     618        paths 
    612619      end 
    613620