Skip to content
Browse files

Allow autoloads to opt out of eager loading

  • Loading branch information...
1 parent ee395fe commit 018dafe574d370165547516ffef43394e11ab4da @josh josh committed Dec 12, 2009
View
2 actionpack/lib/action_controller/deprecated/integration_test.rb
@@ -1,4 +1,2 @@
-require "action_dispatch/testing/integration"
-
ActionController::Integration = ActionDispatch::Integration
ActionController::IntegrationTest = ActionDispatch::IntegrationTest
View
1 actionpack/lib/action_controller/test_case.rb
@@ -1,7 +1,6 @@
require 'active_support/test_case'
require 'rack/session/abstract/id'
require 'action_controller/metal/testing'
-require 'action_dispatch/test_case'
module ActionController
class TestRequest < ActionDispatch::TestRequest #:nodoc:
View
49 actionpack/lib/action_dispatch.rb
@@ -30,38 +30,47 @@ module Rack
module ActionDispatch
extend ActiveSupport::Autoload
- autoload_under "http" do
+ autoload_under 'http' do
autoload :Request
autoload :Response
autoload :StatusCodes
autoload :Utils
end
- autoload_under "middleware" do
- autoload :Callbacks
- autoload :ParamsParser
- autoload :Rescue
- autoload :ShowExceptions
- autoload :Static
- autoload :StringCoercion
- end
+ deferrable do
+ autoload_under 'middleware' do
+ autoload :Callbacks
+ autoload :ParamsParser
+ autoload :Rescue
+ autoload :ShowExceptions
+ autoload :Static
+ autoload :StringCoercion
+ end
- autoload :MiddlewareStack, 'action_dispatch/middleware/stack'
- autoload :Routing
+ autoload :MiddlewareStack, 'action_dispatch/middleware/stack'
+ autoload :Routing
- autoload :HTML, 'action_controller/vendor/html-scanner'
+ module Http
+ autoload :Headers, 'action_dispatch/http/headers'
+ end
- module Http
- extend ActiveSupport::Autoload
+ module Session
+ autoload :AbstractStore, 'action_dispatch/middleware/session/abstract_store'
+ autoload :CookieStore, 'action_dispatch/middleware/session/cookie_store'
+ autoload :MemCacheStore, 'action_dispatch/middleware/session/mem_cache_store'
+ end
- autoload :Headers
+ autoload_under 'testing' do
+ autoload :Assertions
+ autoload :Integration
+ autoload :PerformanceTest
+ autoload :TestProcess
+ autoload :TestRequest
+ autoload :TestResponse
+ end
end
- module Session
- autoload :AbstractStore, 'action_dispatch/middleware/session/abstract_store'
- autoload :CookieStore, 'action_dispatch/middleware/session/cookie_store'
- autoload :MemCacheStore, 'action_dispatch/middleware/session/mem_cache_store'
- end
+ autoload :HTML, 'action_controller/vendor/html-scanner'
end
autoload :Mime, 'action_dispatch/http/mime_type'
View
3 actionpack/lib/action_dispatch/http/request.rb
@@ -6,6 +6,7 @@
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/hash/indifferent_access'
require 'active_support/core_ext/string/access'
+require 'action_dispatch/http/headers'
module ActionDispatch
class Request < Rack::Request
@@ -117,7 +118,7 @@ def accepts
end
end
end
-
+
def if_modified_since
if since = env['HTTP_IF_MODIFIED_SINCE']
Time.rfc2822(since) rescue nil
View
7 actionpack/lib/action_dispatch/test_case.rb
@@ -1,7 +0,0 @@
-require "rack/test"
-require "action_dispatch/testing/assertions"
-require "action_dispatch/testing/integration"
-require "action_dispatch/testing/performance_test"
-require "action_dispatch/testing/test_request"
-require "action_dispatch/testing/test_response"
-require "action_dispatch/testing/integration"
View
1 actionpack/lib/action_dispatch/testing/integration.rb
@@ -2,7 +2,6 @@
require 'uri'
require 'active_support/test_case'
require 'active_support/core_ext/object/metaclass'
-require 'action_dispatch/testing/test_process'
require 'rack/test'
module ActionDispatch
View
20 activesupport/lib/active_support/dependencies/autoload.rb
@@ -2,16 +2,18 @@
module ActiveSupport
module Autoload
-
@@autoloads = {}
@@under_path = nil
@@at_path = nil
+ @@autoload_defer = false
def autoload(const_name, path = @@at_path)
full = [self.name, @@under_path, const_name.to_s, path].compact.join("::")
location = path || Inflector.underscore(full)
- @@autoloads[const_name] = location
+ unless @@autoload_defer
+ @@autoloads[const_name] = location
+ end
super const_name, location
end
@@ -29,9 +31,19 @@ def autoload_at(path)
@@at_path = old_path
end
+ def deferrable
+ old_defer, @@autoload_defer = @@autoload_defer, true
+ yield
+ ensure
+ @@autoload_defer = old_defer
+ end
+
def self.eager_autoload!
- @@autoloads.values.each {|file| require file }
+ @@autoloads.values.each { |file| require file }
end
+ def autoloads
+ @@autoloads
+ end
end
-end
+end

0 comments on commit 018dafe

Please sign in to comment.
Something went wrong with that request. Please try again.