Permalink
Browse files

Reorganize autoloads:

  * A new module (ActiveSupport::Autoload) is provide that extends
    autoloading with new behavior.
  * All autoloads in modules that have extended ActiveSupport::Autoload
    will be eagerly required in threadsafe environments
  * Autoloads can optionally leave off the path if the path is the same
    as full_constant_name.underscore
  * It is possible to specify that a group of autoloads live under an
    additional path. For instance, all of ActionDispatch's middlewares
    are ActionDispatch::MiddlewareName, but they live under 
    "action_dispatch/middlewares/middleware_name"
  * It is possible to specify that a group of autoloads are all found
    at the same path. For instance, a number of exceptions might all
    be declared there.
  * One consequence of this is that testing-related constants are not
    autoloaded. To get the testing helpers for a given component,
    require "component_name/test_case". For instance, "action_controller/test_case".
  * test_help.rb, which is automatically required by a Rails application's
    test helper, requires the test_case.rb for all active components, so
    this change will not be disruptive in existing or new applications.
  • Loading branch information...
Carlhuda
Carlhuda committed Dec 3, 2009
1 parent 399909b commit c1304098cca8a9247a9ad1461a1a343354650843
Showing with 989 additions and 793 deletions.
  1. +18 −16 actionmailer/lib/action_mailer.rb
  2. +1 −1 actionmailer/lib/action_mailer/base.rb
  3. +1 −1 actionmailer/lib/action_mailer/delivery_method/file.rb
  4. +16 −14 actionmailer/lib/action_mailer/mail_helper.rb
  5. +15 −10 actionpack/lib/abstract_controller.rb
  6. +1 −1 actionpack/lib/abstract_controller/rendering_controller.rb
  7. +61 −55 actionpack/lib/action_controller.rb
  8. +1 −1 actionpack/lib/action_controller/base.rb
  9. +4 −3 actionpack/lib/action_controller/caching.rb
  10. +2 −0 actionpack/lib/action_controller/deprecated/integration_test.rb
  11. +1 −1 actionpack/lib/action_controller/metal/compatibility.rb
  12. +1 −1 actionpack/lib/action_controller/metal/helpers.rb
  13. 0 actionpack/lib/action_controller/metal/{rescuable.rb → rescue.rb}
  14. +3 −0 actionpack/lib/action_controller/{testing → }/test_case.rb
  15. +2 −0 actionpack/lib/action_controller/vendor/html-scanner.rb
  16. +21 −20 actionpack/lib/action_dispatch.rb
  17. +2 −2 actionpack/lib/action_dispatch/middleware/show_exceptions.rb
  18. +6 −0 actionpack/lib/action_dispatch/test_case.rb
  19. +12 −14 actionpack/lib/action_view.rb
  20. +1 −1 actionpack/lib/action_view/base.rb
  21. +1 −1 actionpack/lib/action_view/paths.rb
  22. +11 −4 actionpack/lib/action_view/{template → }/template.rb
  23. +77 −75 actionpack/lib/action_view/template/error.rb
  24. +26 −21 actionpack/lib/action_view/template/handler.rb
  25. +49 −47 actionpack/lib/action_view/template/handlers.rb
  26. +2 −2 actionpack/lib/action_view/template/handlers/builder.rb
  27. +2 −2 actionpack/lib/action_view/template/handlers/erb.rb
  28. +2 −2 actionpack/lib/action_view/template/handlers/rjs.rb
  29. +3 −3 actionpack/lib/action_view/template/resolver.rb
  30. +36 −34 actionpack/lib/action_view/template/text.rb
  31. +1 −1 actionpack/lib/action_view/test_case.rb
  32. +13 −13 actionpack/test/abstract/layouts_test.rb
  33. +1 −1 actionpack/test/abstract/render_test.rb
  34. +1 −1 actionpack/test/controller/helper_test.rb
  35. +1 −1 actionpack/test/controller/layout_test.rb
  36. +4 −4 actionpack/test/template/render_test.rb
  37. +23 −20 activemodel/lib/active_model.rb
  38. +1 −0 activemodel/test/cases/helper.rb
  39. +1 −0 activemodel/test/cases/tests_database.rb
  40. +53 −47 activerecord/lib/active_record.rb
  41. +9 −7 activeresource/lib/active_resource.rb
  42. +1 −0 activeresource/test/abstract_unit.rb
  43. +3 −3 activeresource/test/cases/base_test.rb
  44. +29 −26 activesupport/lib/active_support/autoload.rb
  45. +37 −0 activesupport/lib/active_support/dependencies/autoload.rb
  46. +341 −337 activesupport/lib/active_support/testing/performance.rb
  47. +80 −0 activesupport/test/autoload.rb
  48. +2 −0 activesupport/test/fixtures/autoload/another_class.rb
  49. +2 −0 activesupport/test/fixtures/autoload/some_class.rb
  50. +1 −0 railties/lib/rails/console_app.rb
  51. +6 −0 railties/lib/rails/test_help.rb
  52. +1 −0 railties/test/rails_info_controller_test.rb
@@ -25,32 +25,34 @@
$:.unshift(actionpack_path) if File.directory?(actionpack_path)
require 'action_controller'
require 'action_view'
+require 'active_support/autoload'
module ActionMailer
- def self.load_all!
- [Base, Part, ::Text::Format, ::Net::SMTP]
- end
-
- autoload :AdvAttrAccessor, 'action_mailer/adv_attr_accessor'
- autoload :DeprecatedBody, 'action_mailer/deprecated_body'
- autoload :Base, 'action_mailer/base'
- autoload :DeliveryMethod, 'action_mailer/delivery_method'
- autoload :Part, 'action_mailer/part'
- autoload :PartContainer, 'action_mailer/part_container'
- autoload :Quoting, 'action_mailer/quoting'
- autoload :TestCase, 'action_mailer/test_case'
- autoload :TestHelper, 'action_mailer/test_helper'
- autoload :Utils, 'action_mailer/utils'
+ extend ::ActiveSupport::Autoload
+
+ autoload :AdvAttrAccessor
+ autoload :DeprecatedBody
+ autoload :Base
+ autoload :DeliveryMethod
+ autoload :MailHelper
+ autoload :Part
+ autoload :PartContainer
+ autoload :Quoting
+ autoload :TestHelper
+ autoload :Utils
end
module Text
+ extend ActiveSupport::Autoload
+
autoload :Format, 'action_mailer/vendor/text_format'
end
module Net
- autoload :SMTP, 'net/smtp'
+ extend ActiveSupport::Autoload
+
+ autoload :SMTP
end
-autoload :MailHelper, 'action_mailer/mail_helper'
require 'action_mailer/vendor/tmail'
@@ -258,7 +258,7 @@ class Base
include AbstractController::Layouts
include AbstractController::Helpers
- helper MailHelper
+ helper ActionMailer::MailHelper
if Object.const_defined?(:ActionController)
include ActionController::UrlWriter
@@ -6,7 +6,7 @@ module DeliveryMethod
# A delivery method implementation which writes all mails to a file.
class File < Method
self.settings = {
- :location => defined?(Rails) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails"
+ :location => defined?(Rails.root) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails"
}
def perform_delivery(mail)
@@ -1,17 +1,19 @@
-module MailHelper
- # Uses Text::Format to take the text and format it, indented two spaces for
- # each line, and wrapped at 72 columns.
- def block_format(text)
- formatted = text.split(/\n\r\n/).collect { |paragraph|
- Text::Format.new(
- :columns => 72, :first_indent => 2, :body_indent => 2, :text => paragraph
- ).format
- }.join("\n")
+module ActionMailer
+ module MailHelper
+ # Uses Text::Format to take the text and format it, indented two spaces for
+ # each line, and wrapped at 72 columns.
+ def block_format(text)
+ formatted = text.split(/\n\r\n/).collect { |paragraph|
+ Text::Format.new(
+ :columns => 72, :first_indent => 2, :body_indent => 2, :text => paragraph
+ ).format
+ }.join("\n")
- # Make list points stand on their own line
- formatted.gsub!(/[ ]*([*]+) ([^*]*)/) { |s| " #{$1} #{$2.strip}\n" }
- formatted.gsub!(/[ ]*([#]+) ([^#]*)/) { |s| " #{$1} #{$2.strip}\n" }
+ # Make list points stand on their own line
+ formatted.gsub!(/[ ]*([*]+) ([^*]*)/) { |s| " #{$1} #{$2.strip}\n" }
+ formatted.gsub!(/[ ]*([#]+) ([^#]*)/) { |s| " #{$1} #{$2.strip}\n" }
- formatted
+ formatted
+ end
end
-end
+end
@@ -2,15 +2,20 @@
require "active_support/core_ext/module/delegation"
module AbstractController
- autoload :Base, "abstract_controller/base"
- autoload :Callbacks, "abstract_controller/callbacks"
- autoload :Helpers, "abstract_controller/helpers"
- autoload :Layouts, "abstract_controller/layouts"
- autoload :LocalizedCache, "abstract_controller/localized_cache"
- autoload :Logger, "abstract_controller/logger"
- autoload :RenderingController, "abstract_controller/rendering_controller"
+ extend ActiveSupport::Autoload
+
+ autoload :Base
+ autoload :Callbacks
+ autoload :Helpers
+ autoload :Layouts
+ autoload :LocalizedCache
+ autoload :Logger
+ autoload :RenderingController
+
# === Exceptions
- autoload :ActionNotFound, "abstract_controller/exceptions"
- autoload :DoubleRenderError, "abstract_controller/exceptions"
- autoload :Error, "abstract_controller/exceptions"
+ autoload_at "abstract_controller/exceptions" do
+ autoload :ActionNotFound
+ autoload :DoubleRenderError
+ autoload :Error
+ end
end
@@ -115,7 +115,7 @@ def self.body_to_s(body)
# _partial<TrueClass, FalseClass>:: Whether or not the file to look up is a partial
def _determine_template(options)
if options.key?(:text)
- options[:_template] = ActionView::TextTemplate.new(options[:text], format_for_text)
+ options[:_template] = ActionView::Template::Text.new(options[:text], format_for_text)
elsif options.key?(:inline)
handler = ActionView::Template.handler_class_for_extension(options[:type] || "erb")
template = ActionView::Template.new(options[:inline], "inline #{options[:inline].inspect}", handler, {})
@@ -1,66 +1,72 @@
+require "active_support"
+
module ActionController
- autoload :Base, "action_controller/base"
- autoload :Benchmarking, "action_controller/metal/benchmarking"
- autoload :ConditionalGet, "action_controller/metal/conditional_get"
- autoload :Configuration, "action_controller/metal/configuration"
- autoload :Head, "action_controller/metal/head"
- autoload :Helpers, "action_controller/metal/helpers"
- autoload :HideActions, "action_controller/metal/hide_actions"
- autoload :Layouts, "action_controller/metal/layouts"
- autoload :Metal, "action_controller/metal"
- autoload :Middleware, "action_controller/middleware"
- autoload :RackConvenience, "action_controller/metal/rack_convenience"
- autoload :Rails2Compatibility, "action_controller/metal/compatibility"
- autoload :Redirector, "action_controller/metal/redirector"
- autoload :RenderingController, "action_controller/metal/rendering_controller"
- autoload :RenderOptions, "action_controller/metal/render_options"
- autoload :Rescue, "action_controller/metal/rescuable"
- autoload :Responder, "action_controller/metal/responder"
- autoload :Session, "action_controller/metal/session"
- autoload :Testing, "action_controller/metal/testing"
- autoload :UrlFor, "action_controller/metal/url_for"
+ extend ActiveSupport::Autoload
- autoload :Caching, 'action_controller/caching'
- autoload :Dispatcher, 'action_controller/dispatch/dispatcher'
- autoload :Integration, 'action_controller/deprecated/integration_test'
- autoload :IntegrationTest, 'action_controller/deprecated/integration_test'
- autoload :MimeResponds, 'action_controller/metal/mime_responds'
- autoload :PerformanceTest, 'action_controller/deprecated/performance_test'
- autoload :PolymorphicRoutes, 'action_controller/polymorphic_routes'
- autoload :RecordIdentifier, 'action_controller/record_identifier'
- autoload :Routing, 'action_controller/deprecated'
- autoload :SessionManagement, 'action_controller/metal/session_management'
- autoload :TestCase, 'action_controller/testing/test_case'
- autoload :TestProcess, 'action_controller/testing/process'
- autoload :UrlRewriter, 'action_controller/url_rewriter'
- autoload :UrlWriter, 'action_controller/url_rewriter'
+ autoload :Base
+ autoload :Caching
+ autoload :PolymorphicRoutes
+ autoload :RecordIdentifier
+ autoload :UrlRewriter
+ autoload :Translation
+ autoload :Metal
+ autoload :Middleware
- autoload :Verification, 'action_controller/metal/verification'
- autoload :Flash, 'action_controller/metal/flash'
- autoload :RequestForgeryProtection, 'action_controller/metal/request_forgery_protection'
- autoload :Streaming, 'action_controller/metal/streaming'
- autoload :HttpAuthentication, 'action_controller/metal/http_authentication'
- autoload :FilterParameterLogging, 'action_controller/metal/filter_parameter_logging'
- autoload :Translation, 'action_controller/translation'
- autoload :Cookies, 'action_controller/metal/cookies'
+ autoload_under "metal" do
+ autoload :Benchmarking
+ autoload :ConditionalGet
+ autoload :Configuration
+ autoload :Head
+ autoload :Helpers
+ autoload :HideActions
+ autoload :Layouts
+ autoload :MimeResponds
+ autoload :RackConvenience
+ autoload :Compatibility
+ autoload :Redirector
+ autoload :RenderingController
+ autoload :RenderOptions
+ autoload :Rescue
+ autoload :Responder
+ autoload :Session
+ autoload :SessionManagement
+ autoload :UrlFor
+ autoload :Verification
+ autoload :Flash
+ autoload :RequestForgeryProtection
+ autoload :Streaming
+ autoload :HttpAuthentication
+ autoload :FilterParameterLogging
+ autoload :Cookies
+ end
- autoload :ActionControllerError, 'action_controller/metal/exceptions'
- autoload :RenderError, 'action_controller/metal/exceptions'
- autoload :RoutingError, 'action_controller/metal/exceptions'
- autoload :MethodNotAllowed, 'action_controller/metal/exceptions'
- autoload :NotImplemented, 'action_controller/metal/exceptions'
- autoload :UnknownController, 'action_controller/metal/exceptions'
- autoload :MissingFile, 'action_controller/metal/exceptions'
- autoload :RenderError, 'action_controller/metal/exceptions'
- autoload :SessionOverflowError, 'action_controller/metal/exceptions'
- autoload :UnknownHttpMethod, 'action_controller/metal/exceptions'
-end
+ autoload :Dispatcher, 'action_controller/dispatch/dispatcher'
+ autoload :PerformanceTest, 'action_controller/deprecated/performance_test'
+ autoload :Routing, 'action_controller/deprecated'
+ autoload :Integration, 'action_controller/deprecated/integration_test'
+ autoload :IntegrationTest, 'action_controller/deprecated/integration_test'
-autoload :HTML, 'action_controller/vendor/html-scanner'
-autoload :AbstractController, 'abstract_controller'
+ autoload :UrlWriter, 'action_controller/url_rewriter'
+
+ autoload_at "action_controller/metal/exceptions" do
+ autoload :ActionControllerError
+ autoload :RenderError
+ autoload :RoutingError
+ autoload :MethodNotAllowed
+ autoload :NotImplemented
+ autoload :UnknownController
+ autoload :MissingFile
+ autoload :RenderError
+ autoload :SessionOverflowError
+ autoload :UnknownHttpMethod
+ end
+end
+# All of these simply register additional autoloads
+require 'abstract_controller'
require 'action_dispatch'
require 'action_view'
+require 'action_controller/vendor/html-scanner'
# Common ActiveSupport usage in ActionController
require "active_support/concern"
@@ -24,7 +24,7 @@ class Base < Metal
include ActionController::MimeResponds
# Rails 2.x compatibility
- include ActionController::Rails2Compatibility
+ include ActionController::Compatibility
include ActionController::Cookies
include ActionController::Session
@@ -30,10 +30,11 @@ module ActionController #:nodoc:
# config.action_controller.cache_store = MyOwnStore.new("parameter")
module Caching
extend ActiveSupport::Concern
+ extend ActiveSupport::Autoload
- autoload :Actions, 'action_controller/caching/actions'
- autoload :Fragments, 'action_controller/caching/fragments'
- autoload :Pages, 'action_controller/caching/pages'
+ autoload :Actions
+ autoload :Fragments
+ autoload :Pages
autoload :Sweeper, 'action_controller/caching/sweeping'
autoload :Sweeping, 'action_controller/caching/sweeping'
@@ -1,2 +1,4 @@
+require "action_dispatch/testing/integration"
+
ActionController::Integration = ActionDispatch::Integration
ActionController::IntegrationTest = ActionDispatch::IntegrationTest
@@ -1,5 +1,5 @@
module ActionController
- module Rails2Compatibility
+ module Compatibility
extend ActiveSupport::Concern
class ::ActionController::ActionControllerError < StandardError #:nodoc:
@@ -52,7 +52,7 @@ module Helpers
included do
# Set the default directory for helpers
extlib_inheritable_accessor(:helpers_dir) do
- defined?(Rails) ? "#{Rails.root}/app/helpers" : "app/helpers"
+ defined?(Rails.root) ? "#{Rails.root}/app/helpers" : "app/helpers"
end
end
@@ -1,5 +1,8 @@
require 'active_support/test_case'
require 'rack/session/abstract/id'
+require 'action_controller/metal/testing'
+require 'action_controller/testing/process'
+require 'action_dispatch/test_case'
module ActionController
class TestRequest < ActionDispatch::TestRequest #:nodoc:
@@ -1,6 +1,8 @@
$LOAD_PATH << "#{File.dirname(__FILE__)}/html-scanner"
module HTML
+ extend ActiveSupport::Autoload
+
autoload :CDATA, 'html/node'
autoload :Document, 'html/document'
autoload :FullSanitizer, 'html/sanitizer'
@@ -28,37 +28,38 @@ module Rack
end
module ActionDispatch
- autoload :Request, 'action_dispatch/http/request'
- autoload :Response, 'action_dispatch/http/response'
- autoload :StatusCodes, 'action_dispatch/http/status_codes'
- autoload :Utils, 'action_dispatch/http/utils'
+ extend ActiveSupport::Autoload
- autoload :Callbacks, 'action_dispatch/middleware/callbacks'
- autoload :MiddlewareStack, 'action_dispatch/middleware/stack'
- autoload :ParamsParser, 'action_dispatch/middleware/params_parser'
- autoload :Rescue, 'action_dispatch/middleware/rescue'
- autoload :ShowExceptions, 'action_dispatch/middleware/show_exceptions'
- autoload :Static, 'action_dispatch/middleware/static'
- autoload :StringCoercion, 'action_dispatch/middleware/string_coercion'
+ autoload_under "http" do
+ autoload :Request
+ autoload :Response
+ autoload :StatusCodes
+ autoload :Utils
+ end
- autoload :Routing, 'action_dispatch/routing'
+ autoload_under "middleware" do
+ autoload :Callbacks
+ autoload :ParamsParser
+ autoload :Rescue
+ autoload :ShowExceptions
+ autoload :Static
+ autoload :StringCoercion
+ end
- autoload :Assertions, 'action_dispatch/testing/assertions'
- autoload :Integration, 'action_dispatch/testing/integration'
- autoload :IntegrationTest, 'action_dispatch/testing/integration'
- autoload :PerformanceTest, 'action_dispatch/testing/performance_test'
- autoload :TestRequest, 'action_dispatch/testing/test_request'
- autoload :TestResponse, 'action_dispatch/testing/test_response'
+ autoload :MiddlewareStack, 'action_dispatch/middleware/stack'
+ autoload :Routing
autoload :HTML, 'action_controller/vendor/html-scanner'
module Http
- autoload :Headers, 'action_dispatch/http/headers'
+ extend ActiveSupport::Autoload
+
+ autoload :Headers
end
module Session
autoload :AbstractStore, 'action_dispatch/middleware/session/abstract_store'
- autoload :CookieStore, 'action_dispatch/middleware/session/cookie_store'
+ autoload :CookieStore, 'action_dispatch/middleware/session/cookie_store'
autoload :MemCacheStore, 'action_dispatch/middleware/session/mem_cache_store'
end
end
Oops, something went wrong.

1 comment on commit c130409

@matthuhiggins

This comment has been minimized.

Show comment
Hide comment
@matthuhiggins

matthuhiggins Dec 3, 2009

Is there a way for a plugin to use autoload? In my case, I have a plugin that only needs to load when ActionController::Base is referenced, and another plugin that is included into ActiveRecord::ConnectionAdapters. Since most plugins today currently do not autoload, they force the entire environment to load when running tests and starting up.

It seems what I want is the ability to autoload multiple files for a given module. Is there another way?

Is there a way for a plugin to use autoload? In my case, I have a plugin that only needs to load when ActionController::Base is referenced, and another plugin that is included into ActiveRecord::ConnectionAdapters. Since most plugins today currently do not autoload, they force the entire environment to load when running tests and starting up.

It seems what I want is the ability to autoload multiple files for a given module. Is there another way?

Please sign in to comment.