From 924fa084e81b8b2f5ae9eab93d6b711c2b6b89d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 23 Jan 2010 17:13:25 +0100 Subject: First steps into making Plugin < Engine. --- railties/lib/rails/application.rb | 5 +++++ railties/lib/rails/application/finisher.rb | 12 ++++++++++++ railties/lib/rails/engine.rb | 20 ++++++++++---------- railties/lib/rails/paths.rb | 3 ++- 4 files changed, 29 insertions(+), 11 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 8f562350b4..1286d437c7 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -51,6 +51,11 @@ module Rails end end + # Application is always reloadable when config.cache_classes is false. + def reloadable?(app) + true + end + def initialize environment = config.paths.config.environment.to_a.first require environment if environment diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 4e7fffd0b3..2ac881ac11 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -3,6 +3,18 @@ module Rails module Finisher include Initializable + initializer :ensure_load_once_paths_as_subset do + extra = ActiveSupport::Dependencies.load_once_paths - + ActiveSupport::Dependencies.load_paths + + unless extra.empty? + abort <<-end_error + load_once_paths must be a subset of the load_paths. + Extra items in load_once_paths: #{extra * ','} + end_error + end + end + initializer :add_builtin_route do |app| if Rails.env.development? app.config.action_dispatch.route_files << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index cf6ca7c3f5..b11c1ac73e 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -42,6 +42,10 @@ module Rails delegate :middleware, :paths, :root, :config, :to => :'self.class' + def reloadable?(app) + app.config.reload_plugins + end + # Add configured load paths to ruby load paths and remove duplicates. initializer :set_load_path do config.load_paths.reverse_each do |path| @@ -52,21 +56,17 @@ module Rails # Set the paths from which Rails will automatically load source files, # and the load_once paths. - initializer :set_autoload_paths do + initializer :set_autoload_paths do |app| ActiveSupport::Dependencies.load_paths.concat(config.load_paths) - ActiveSupport::Dependencies.load_once_paths.concat(config.load_once_paths) - - extra = ActiveSupport::Dependencies.load_once_paths - - ActiveSupport::Dependencies.load_paths - unless extra.empty? - abort <<-end_error - load_once_paths must be a subset of the load_paths. - Extra items in load_once_paths: #{extra * ','} - end_error + if reloadable?(app) + ActiveSupport::Dependencies.load_once_paths.concat(config.load_once_paths) + else + ActiveSupport::Dependencies.load_once_paths.concat(config.load_paths) end # Freeze so future modifications will fail rather than do nothing mysteriously + config.load_paths.freeze config.load_once_paths.freeze end diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index d81af3c709..069371aa9c 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -73,7 +73,7 @@ module Rails @load_once = @options[:load_once] @eager_load = @options[:eager_load] - @load_path = @options[:load_path] || @eager_load + @load_path = @options[:load_path] || @eager_load || @load_once @root.all_paths << self end @@ -98,6 +98,7 @@ module Rails def load_once! @load_once = true + @load_path = true end def load_once? -- cgit v1.2.3