From 4ae79367277954bf6616151b03cbe0660808f9bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 22 Jan 2010 16:24:44 +0100 Subject: Got tests working once again. --- railties/lib/rails/application.rb | 4 +--- railties/lib/rails/configuration.rb | 28 +++++++++++++++++----------- railties/lib/rails/engine.rb | 4 +++- railties/lib/rails/paths.rb | 18 ++++++++---------- 4 files changed, 29 insertions(+), 25 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 9be9584873..db1f62f381 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -2,8 +2,6 @@ require 'fileutils' module Rails class Application < Engine - include Initializable - class << self alias :configure :class_eval delegate :initialize!, :load_tasks, :load_generators, :root, :to => :instance @@ -122,7 +120,7 @@ module Rails app.call(env) end - initializer :add_builtin_route do |app| + initializer :add_builtin_route, :before => :build_middleware_stack do |app| if Rails.env.development? app.route_configuration_files << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') end diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 9176809dbd..01fab1e474 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -81,15 +81,13 @@ module Rails def paths @paths ||= begin paths = Rails::Application::Root.new(@root) - paths.app "app", :load_path => true - paths.app_glob "app/*", :load_path => true, :eager_load => true - paths.app.controllers "app/controllers", :eager_load => true - paths.app.metals "app/metal" + paths.app "app", :eager_load => true, :glob => "*" + paths.app.controllers "app/controllers", :eager_load => true + paths.app.metals "app/metal", :eager_load => true paths.app.views "app/views" paths.lib "lib", :load_path => true paths.config "config" - paths.config.environment "config/environments/#{Rails.env}.rb" - paths.config.environments "config/environments", :glob => "#{Rails.env}.rb" + paths.config.environment "config/environments", :glob => "#{Rails.env}.rb" paths.config.initializers "config/initializers" paths.config.locales "config/locales" paths.config.routes "config/routes.rb" @@ -112,10 +110,6 @@ module Rails def load_paths @load_paths ||= paths.load_paths end - - def controller_paths - paths.app.controllers.to_a.uniq - end end class Configuration < Engine::Configuration @@ -142,7 +136,7 @@ module Rails def paths @paths ||= begin paths = super - paths.app.controllers << builtin_directories + paths.app.controllers.concat(builtin_directories) paths.config.database "config/database.yml" paths.log "log/#{Rails.env}.log" paths.tmp "tmp" @@ -238,6 +232,18 @@ module Rails paths.config.log.to_a.first end + def controller_paths=(value) + ActiveSupport::Deprecation.warn "config.controller_paths= is deprecated, " << + "please do config.paths.app.controllers= instead", caller + paths.app.controllers = value + end + + def controller_paths + ActiveSupport::Deprecation.warn "config.controller_paths is deprecated, " << + "please do config.paths.app.controllers instead", caller + paths.app.controllers.to_a.uniq + end + def cache_store @cache_store ||= begin if File.exist?("#{root}/tmp/cache/") diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index a0139f9983..effbfee6c1 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -50,7 +50,9 @@ module Rails # Add configured load paths to ruby load paths and remove duplicates. initializer :set_load_path, :before => :container do - config.paths.add_to_load_path + expand_load_path(config.load_paths).reverse_each do |path| + $LOAD_PATH.unshift(path) if File.directory?(path) + end $LOAD_PATH.uniq! end diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index b3d105d8c7..d81af3c709 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -39,6 +39,7 @@ module Rails all_paths.map { |path| path.paths if path.eager_load? }.compact.flatten.uniq end + # TODO Discover why do we need to call uniq! here def all_paths @all_paths.uniq! @all_paths @@ -48,12 +49,6 @@ module Rails all_paths.map { |path| path.paths if path.load_path? }.compact.flatten.uniq end - def add_to_load_path - load_paths.reverse_each do |path| - $LOAD_PATH.unshift(path) if File.directory?(path) - end - end - def push(*) raise "Application root can only have one physical path" end @@ -74,7 +69,7 @@ module Rails @children = {} @root = root @paths = paths.flatten - @glob = @options[:glob] || "**/*.rb" + @glob = @options.delete(:glob) @load_once = @options[:load_once] @eager_load = @options[:eager_load] @@ -128,10 +123,13 @@ module Rails def paths raise "You need to set a path root" unless @root.path - - @paths.map do |path| - path.index('/') == 0 ? path : File.expand_path(File.join(@root.path, path)) + result = @paths.map do |p| + path = File.expand_path(p, @root.path) + @glob ? Dir[File.join(path, @glob)] : path end + result.flatten! + result.uniq! + result end alias to_a paths -- cgit v1.2.3