2009年9月1日火曜日

[Rails][CodeReading] Rails::Initializer (35) initialize_routing

Initializer.process で35番目に呼ばれる initialize_routing メソッド。

def initialize_routing
return unless configuration.frameworks.include?(:action_controller)

ActionController::Routing.controller_paths += configuration.controller_paths
ActionController::Routing::Routes.add_configuration_file(configuration.routes_configuration_file)
ActionController::Routing::Routes.reload!
end

丁寧なコメントがついているので、そのまま引用。

If Action Controller is not one of the loaded frameworks (Configuration#frameworks) this does nothing. Otherwise, it loads the routing definitions and sets up loading module used to lazily load controllers (Configuration#controller_paths).
(もしAction Controller がロードされていなければ、何もしない。ロードされていたら、ルーティング定義を読み込んで、(後でコントローラをロードするのに使われる)ロードモジュールをセットアップする。)


Configuration.controller_paths のデフォルト値は、

def default_controller_paths
paths = [File.join(root_path, 'app', 'controllers')]
paths.concat builtin_directories
paths
end

Configuration.routes_configuration_file のデフォルト値は、

def default_routes_configuration_file
File.join(root_path, 'config', 'routes.rb')
end

とどちらもお馴染みのパスとなっています。

[Rails][CodeReading] Railsの初期化コードを読む (イントロ&目次)

0 件のコメント:

コメントを投稿