diff options
author | José Valim <jose.valim@gmail.com> | 2012-08-01 20:54:22 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-08-21 14:47:19 -0300 |
commit | 2801786e1a51b7cf7d7c3fd72b5fc9974f83f435 (patch) | |
tree | 2bc2efda7c5d724ba4d85373879e75d9709355df /railties | |
parent | a1687e48cba2f0447f02248939cde05502562e87 (diff) | |
download | rails-2801786e1a51b7cf7d7c3fd72b5fc9974f83f435.tar.gz rails-2801786e1a51b7cf7d7c3fd72b5fc9974f83f435.tar.bz2 rails-2801786e1a51b7cf7d7c3fd72b5fc9974f83f435.zip |
Get rid of config.preload_frameworks in favor of config.eager_load_namespaces
The new option allows any Ruby namespace to be registered and set
up for eager load. We are effectively exposing the structure existing
in Rails since v3.0 for all developers in order to make their applications
thread-safe and CoW friendly.
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/application.rb | 7 | ||||
-rw-r--r-- | railties/lib/rails/application/bootstrap.rb | 9 | ||||
-rw-r--r-- | railties/lib/rails/application/configuration.rb | 3 | ||||
-rw-r--r-- | railties/lib/rails/application/finisher.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails/engine.rb | 5 | ||||
-rw-r--r-- | railties/lib/rails/railtie.rb | 3 | ||||
-rw-r--r-- | railties/lib/rails/railtie/configuration.rb | 10 | ||||
-rw-r--r-- | railties/test/application/configuration_test.rb | 16 | ||||
-rw-r--r-- | railties/test/application/rake_test.rb | 1 |
9 files changed, 18 insertions, 38 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 32039c26f3..ae872f2bb0 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -83,13 +83,6 @@ module Rails @queue = nil end - # Eager load all dependencies before eager loading - # the application. - def eager_load! - railties.each(&:eager_load!) - super - end - # Returns true if the application is initialized. def initialized? @initialized diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index 1e5f95336f..a1bc95550b 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -16,7 +16,7 @@ module Rails initializer :set_eager_load, :group => :all do if config.eager_load.nil? warn <<-INFO -config.eager_load is set to nil. Please update your config/environments file accordingly: +config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly: * development - set it to false * test - set it to false (unless you use a tool that preloads your test environment) @@ -27,13 +27,6 @@ INFO end end - # Preload all frameworks specified by the Configuration#frameworks. - # Used by Passenger to ensure everything's loaded before forking and - # to avoid autoload race conditions in JRuby. - initializer :preload_frameworks, :group => :all do - ActiveSupport::Autoload.eager_autoload! if config.preload_frameworks - end - # Initialize the logger early in the stack in case we need to log some deprecation. initializer :initialize_logger, :group => :all do Rails.logger ||= config.logger || begin diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 77d89f0cb9..5c7cf412ac 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -9,7 +9,7 @@ module Rails :cache_classes, :cache_store, :consider_all_requests_local, :console, :eager_load, :exceptions_app, :file_watcher, :filter_parameters, :force_ssl, :helpers_paths, :logger, :log_formatter, :log_tags, - :preload_frameworks, :railties_order, :relative_url_root, :secret_token, + :railties_order, :relative_url_root, :secret_token, :serve_static_assets, :ssl_options, :static_cache_control, :session_options, :time_zone, :reload_classes_only_on_change, :queue, :queue_consumer @@ -95,7 +95,6 @@ module Rails # after boot, and disables reloading code on every request, as these are # fundamentally incompatible with thread safety. def threadsafe! - @preload_frameworks = true @cache_classes = true @eager_load = true self diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index ba9f501546..1952a0fc3a 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -52,7 +52,7 @@ module Rails initializer :eager_load! do if config.eager_load ActiveSupport.run_load_hooks(:before_eager_load, self) - eager_load! + config.eager_load_namespaces.each(&:eager_load!) end end diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 40f35ae5a6..3a5caf9f62 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -339,11 +339,16 @@ module Rails class << self attr_accessor :called_from, :isolated + alias :isolated? :isolated alias :engine_name :railtie_name + delegate :eager_load!, to: :instance + def inherited(base) unless base.abstract_railtie? + Rails::Railtie::Configuration.eager_load_namespaces << base + base.called_from = begin # Remove the line number from backtraces making sure we don't leave anything behind call_stack = caller.map { |p| p.sub(/:\d+.*/, '') } diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index 1cb99463cc..fba685c769 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -178,9 +178,6 @@ module Rails @config ||= Railtie::Configuration.new end - def eager_load! - end - def railtie_namespace @railtie_namespace ||= self.class.parents.detect { |n| n.respond_to?(:railtie_namespace) } end diff --git a/railties/lib/rails/railtie/configuration.rb b/railties/lib/rails/railtie/configuration.rb index 1c6b3769a5..9dc8843887 100644 --- a/railties/lib/rails/railtie/configuration.rb +++ b/railties/lib/rails/railtie/configuration.rb @@ -7,6 +7,16 @@ module Rails @@options ||= {} end + # Expose the eager_load_namespaces at "module" level for convenience. + def self.eager_load_namespaces #:nodoc: + @@eager_load_namespaces ||= [] + end + + # All namespaces that are eager loaded + def eager_load_namespaces + @@eager_load_namespaces ||= [] + end + # Add files that should be watched for change. def watchable_files @@watchable_files ||= [] diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index eb808f5473..26f8aad95b 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -176,22 +176,6 @@ module ApplicationTests end end - test "frameworks are not preloaded by default" do - require "#{app_path}/config/environment" - - assert ActionController.autoload?(:Caching) - end - - test "frameworks are preloaded with config.preload_frameworks is set" do - add_to_config <<-RUBY - config.preload_frameworks = true - RUBY - - require "#{app_path}/config/environment" - - assert !ActionView.autoload?(:AssetPaths) - end - test "filter_parameters should be able to set via config.filter_parameters" do add_to_config <<-RUBY config.filter_parameters += [ :foo, 'bar', lambda { |key, value| diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 5d7fa7e397..b05fe3aed5 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -75,7 +75,6 @@ module ApplicationTests RUBY output = Dir.chdir(app_path){ `rake do_nothing` } - puts output assert_match "Hello world", output end |