Skip to content
This repository
Browse code

Allow autoloads to opt out of eager loading

  • Loading branch information...
commit 018dafe574d370165547516ffef43394e11ab4da 1 parent ee395fe
Joshua Peek josh authored
2  actionpack/lib/action_controller/deprecated/integration_test.rb
... ... @@ -1,4 +1,2 @@
1   -require "action_dispatch/testing/integration"
2   -
3 1 ActionController::Integration = ActionDispatch::Integration
4 2 ActionController::IntegrationTest = ActionDispatch::IntegrationTest
1  actionpack/lib/action_controller/test_case.rb
... ... @@ -1,7 +1,6 @@
1 1 require 'active_support/test_case'
2 2 require 'rack/session/abstract/id'
3 3 require 'action_controller/metal/testing'
4   -require 'action_dispatch/test_case'
5 4
6 5 module ActionController
7 6 class TestRequest < ActionDispatch::TestRequest #:nodoc:
49 actionpack/lib/action_dispatch.rb
@@ -30,38 +30,47 @@ module Rack
30 30 module ActionDispatch
31 31 extend ActiveSupport::Autoload
32 32
33   - autoload_under "http" do
  33 + autoload_under 'http' do
34 34 autoload :Request
35 35 autoload :Response
36 36 autoload :StatusCodes
37 37 autoload :Utils
38 38 end
39 39
40   - autoload_under "middleware" do
41   - autoload :Callbacks
42   - autoload :ParamsParser
43   - autoload :Rescue
44   - autoload :ShowExceptions
45   - autoload :Static
46   - autoload :StringCoercion
47   - end
  40 + deferrable do
  41 + autoload_under 'middleware' do
  42 + autoload :Callbacks
  43 + autoload :ParamsParser
  44 + autoload :Rescue
  45 + autoload :ShowExceptions
  46 + autoload :Static
  47 + autoload :StringCoercion
  48 + end
48 49
49   - autoload :MiddlewareStack, 'action_dispatch/middleware/stack'
50   - autoload :Routing
  50 + autoload :MiddlewareStack, 'action_dispatch/middleware/stack'
  51 + autoload :Routing
51 52
52   - autoload :HTML, 'action_controller/vendor/html-scanner'
  53 + module Http
  54 + autoload :Headers, 'action_dispatch/http/headers'
  55 + end
53 56
54   - module Http
55   - extend ActiveSupport::Autoload
  57 + module Session
  58 + autoload :AbstractStore, 'action_dispatch/middleware/session/abstract_store'
  59 + autoload :CookieStore, 'action_dispatch/middleware/session/cookie_store'
  60 + autoload :MemCacheStore, 'action_dispatch/middleware/session/mem_cache_store'
  61 + end
56 62
57   - autoload :Headers
  63 + autoload_under 'testing' do
  64 + autoload :Assertions
  65 + autoload :Integration
  66 + autoload :PerformanceTest
  67 + autoload :TestProcess
  68 + autoload :TestRequest
  69 + autoload :TestResponse
  70 + end
58 71 end
59 72
60   - module Session
61   - autoload :AbstractStore, 'action_dispatch/middleware/session/abstract_store'
62   - autoload :CookieStore, 'action_dispatch/middleware/session/cookie_store'
63   - autoload :MemCacheStore, 'action_dispatch/middleware/session/mem_cache_store'
64   - end
  73 + autoload :HTML, 'action_controller/vendor/html-scanner'
65 74 end
66 75
67 76 autoload :Mime, 'action_dispatch/http/mime_type'
3  actionpack/lib/action_dispatch/http/request.rb
@@ -6,6 +6,7 @@
6 6 require 'active_support/core_ext/array/wrap'
7 7 require 'active_support/core_ext/hash/indifferent_access'
8 8 require 'active_support/core_ext/string/access'
  9 +require 'action_dispatch/http/headers'
9 10
10 11 module ActionDispatch
11 12 class Request < Rack::Request
@@ -117,7 +118,7 @@ def accepts
117 118 end
118 119 end
119 120 end
120   -
  121 +
121 122 def if_modified_since
122 123 if since = env['HTTP_IF_MODIFIED_SINCE']
123 124 Time.rfc2822(since) rescue nil
7 actionpack/lib/action_dispatch/test_case.rb
... ... @@ -1,7 +0,0 @@
1   -require "rack/test"
2   -require "action_dispatch/testing/assertions"
3   -require "action_dispatch/testing/integration"
4   -require "action_dispatch/testing/performance_test"
5   -require "action_dispatch/testing/test_request"
6   -require "action_dispatch/testing/test_response"
7   -require "action_dispatch/testing/integration"
1  actionpack/lib/action_dispatch/testing/integration.rb
@@ -2,7 +2,6 @@
2 2 require 'uri'
3 3 require 'active_support/test_case'
4 4 require 'active_support/core_ext/object/metaclass'
5   -require 'action_dispatch/testing/test_process'
6 5 require 'rack/test'
7 6
8 7 module ActionDispatch
20 activesupport/lib/active_support/dependencies/autoload.rb
@@ -2,16 +2,18 @@
2 2
3 3 module ActiveSupport
4 4 module Autoload
5   -
6 5 @@autoloads = {}
7 6 @@under_path = nil
8 7 @@at_path = nil
  8 + @@autoload_defer = false
9 9
10 10 def autoload(const_name, path = @@at_path)
11 11 full = [self.name, @@under_path, const_name.to_s, path].compact.join("::")
12 12 location = path || Inflector.underscore(full)
13 13
14   - @@autoloads[const_name] = location
  14 + unless @@autoload_defer
  15 + @@autoloads[const_name] = location
  16 + end
15 17 super const_name, location
16 18 end
17 19
@@ -29,9 +31,19 @@ def autoload_at(path)
29 31 @@at_path = old_path
30 32 end
31 33
  34 + def deferrable
  35 + old_defer, @@autoload_defer = @@autoload_defer, true
  36 + yield
  37 + ensure
  38 + @@autoload_defer = old_defer
  39 + end
  40 +
32 41 def self.eager_autoload!
33   - @@autoloads.values.each {|file| require file }
  42 + @@autoloads.values.each { |file| require file }
34 43 end
35 44
  45 + def autoloads
  46 + @@autoloads
  47 + end
36 48 end
37   -end
  49 +end

0 comments on commit 018dafe

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