Skip to content
This repository
Browse code

Use autoload instead of explicit requires for ActionController

  • Loading branch information...
commit 31ce92f7b5784bc5b6a441e88cd734c7b8b1c58f 1 parent 6de1060
Joshua Peek authored November 23, 2008

Showing 23 changed files with 73 additions and 96 deletions. Show diff stats Hide diff stats

  1. 96  actionpack/lib/action_controller.rb
  2. 14  actionpack/lib/action_controller/base.rb
  3. 18  actionpack/lib/action_controller/caching.rb
  4. 1  actionpack/lib/action_controller/cgi_process.rb
  5. 4  actionpack/lib/action_controller/integration.rb
  6. 1  actionpack/lib/action_controller/performance_test.rb
  7. 1  actionpack/lib/action_controller/rack_process.rb
  8. 1  actionpack/lib/action_controller/request_profiler.rb
  9. 4  actionpack/lib/action_controller/resources.rb
  10. 1  actionpack/lib/action_controller/routing.rb
  11. 2  actionpack/lib/action_controller/routing/route_set.rb
  12. 7  actionpack/lib/action_controller/session_management.rb
  13. 2  actionpack/lib/action_view/test_case.rb
  14. 1  actionpack/test/activerecord/active_record_store_test.rb
  15. 1  actionpack/test/controller/cgi_test.rb
  16. 2  actionpack/test/controller/dispatcher_test.rb
  17. 2  actionpack/test/controller/integration_test.rb
  18. 2  actionpack/test/controller/integration_upload_test.rb
  19. 1  actionpack/test/controller/rack_test.rb
  20. 1  actionpack/test/controller/request_test.rb
  21. 1  actionpack/test/controller/routing_test.rb
  22. 3  actionpack/test/controller/session/cookie_store_test.rb
  23. 3  actionpack/test/controller/session/mem_cache_store_test.rb
96  actionpack/lib/action_controller.rb
@@ -32,47 +32,63 @@
32 32
 end
33 33
 
34 34
 $:.unshift "#{File.dirname(__FILE__)}/action_controller/vendor/html-scanner"
35  
-require 'action_controller/vendor/rack'
36 35
 
37  
-require 'action_controller/base'
38  
-require 'action_controller/request'
39  
-require 'action_controller/rescue'
40  
-require 'action_controller/benchmarking'
41  
-require 'action_controller/flash'
42  
-require 'action_controller/filters'
43  
-require 'action_controller/layout'
44  
-require 'action_controller/mime_responds'
45  
-require 'action_controller/helpers'
46  
-require 'action_controller/cookies'
47  
-require 'action_controller/cgi_process'
48  
-require 'action_controller/caching'
49  
-require 'action_controller/verification'
50  
-require 'action_controller/streaming'
51  
-require 'action_controller/session_management'
52  
-require 'action_controller/http_authentication'
53  
-require 'action_controller/rack_process'
54  
-require 'action_controller/record_identifier'
55  
-require 'action_controller/request_forgery_protection'
56  
-require 'action_controller/headers'
57  
-require 'action_controller/translation'
  36
+module ActionController
  37
+  # TODO: Review explicit to see if they will automatically be handled by
  38
+  # the initilizer if they are really needed.
  39
+  def self.load_all!
  40
+    [Base, CgiRequest, CgiResponse, RackRequest, RackRequest, Http::Headers, UrlRewriter, UrlWriter]
  41
+  end
58 42
 
59  
-require 'action_view'
  43
+  autoload :AbstractRequest, 'action_controller/request'
  44
+  autoload :AbstractResponse, 'action_controller/response'
  45
+  autoload :Base, 'action_controller/base'
  46
+  autoload :Benchmarking, 'action_controller/benchmarking'
  47
+  autoload :Caching, 'action_controller/caching'
  48
+  autoload :CgiRequest, 'action_controller/cgi_process'
  49
+  autoload :CgiResponse, 'action_controller/cgi_process'
  50
+  autoload :Cookies, 'action_controller/cookies'
  51
+  autoload :Dispatcher, 'action_controller/dispatcher'
  52
+  autoload :Filters, 'action_controller/filters'
  53
+  autoload :Flash, 'action_controller/flash'
  54
+  autoload :Helpers, 'action_controller/helpers'
  55
+  autoload :HttpAuthentication, 'action_controller/http_authentication'
  56
+  autoload :IntegrationTest, 'action_controller/integration'
  57
+  autoload :Layout, 'action_controller/layout'
  58
+  autoload :MimeResponds, 'action_controller/mime_responds'
  59
+  autoload :PolymorphicRoutes, 'action_controller/polymorphic_routes'
  60
+  autoload :RackRequest, 'action_controller/rack_process'
  61
+  autoload :RackResponse, 'action_controller/rack_process'
  62
+  autoload :RecordIdentifier, 'action_controller/record_identifier'
  63
+  autoload :RequestForgeryProtection, 'action_controller/request_forgery_protection'
  64
+  autoload :Rescue, 'action_controller/rescue'
  65
+  autoload :Resources, 'action_controller/resources'
  66
+  autoload :Routing, 'action_controller/routing'
  67
+  autoload :SessionManagement, 'action_controller/session_management'
  68
+  autoload :StatusCodes, 'action_controller/status_codes'
  69
+  autoload :Streaming, 'action_controller/streaming'
  70
+  autoload :TestCase, 'action_controller/test_case'
  71
+  autoload :TestProcess, 'action_controller/test_process'
  72
+  autoload :Translation, 'action_controller/translation'
  73
+  autoload :UrlRewriter, 'action_controller/url_rewriter'
  74
+  autoload :UrlWriter, 'action_controller/url_rewriter'
  75
+  autoload :Verification, 'action_controller/verification'
60 76
 
61  
-ActionController::Base.class_eval do
62  
-  include ActionController::Flash
63  
-  include ActionController::Filters
64  
-  include ActionController::Layout
65  
-  include ActionController::Benchmarking
66  
-  include ActionController::Rescue
67  
-  include ActionController::MimeResponds
68  
-  include ActionController::Helpers
69  
-  include ActionController::Cookies
70  
-  include ActionController::Caching
71  
-  include ActionController::Verification
72  
-  include ActionController::Streaming
73  
-  include ActionController::SessionManagement
74  
-  include ActionController::HttpAuthentication::Basic::ControllerMethods
75  
-  include ActionController::RecordIdentifier
76  
-  include ActionController::RequestForgeryProtection
77  
-  include ActionController::Translation
  77
+  module Http
  78
+    autoload :Headers, 'action_controller/headers'
  79
+  end
78 80
 end
  81
+
  82
+class CGI
  83
+  class Session
  84
+    autoload :ActiveRecordStore, 'action_controller/session/active_record_store'
  85
+    autoload :CookieStore, 'action_controller/session/cookie_store'
  86
+    autoload :DRbStore, 'action_controller/session/drb_store'
  87
+    autoload :MemCacheStore, 'action_controller/session/mem_cache_store'
  88
+  end
  89
+end
  90
+
  91
+autoload :Mime, 'action_controller/mime_type'
  92
+autoload :Rack, 'action_controller/vendor/rack'
  93
+
  94
+ActionController.load_all!
14  actionpack/lib/action_controller/base.rb
... ...
@@ -1,10 +1,3 @@
1  
-require 'action_controller/mime_type'
2  
-require 'action_controller/request'
3  
-require 'action_controller/response'
4  
-require 'action_controller/routing'
5  
-require 'action_controller/resources'
6  
-require 'action_controller/url_rewriter'
7  
-require 'action_controller/status_codes'
8 1
 require 'action_view'
9 2
 require 'drb'
10 3
 require 'set'
@@ -1332,4 +1325,11 @@ def process_cleanup
1332 1325
         close_session
1333 1326
       end
1334 1327
   end
  1328
+
  1329
+  Base.class_eval do
  1330
+    include Flash, Filters, Layout, Benchmarking, Rescue, MimeResponds, Helpers
  1331
+    include Cookies, Caching, Verification, Streaming
  1332
+    include SessionManagement, HttpAuthentication::Basic::ControllerMethods
  1333
+    include RecordIdentifier, RequestForgeryProtection, Translation
  1334
+  end
1335 1335
 end
18  actionpack/lib/action_controller/caching.rb
@@ -2,13 +2,6 @@
2 2
 require 'uri'
3 3
 require 'set'
4 4
 
5  
-require 'action_controller/caching/pages'
6  
-require 'action_controller/caching/actions'
7  
-require 'action_controller/caching/sql_cache'
8  
-require 'action_controller/caching/sweeping'
9  
-require 'action_controller/caching/fragments'
10  
-
11  
-
12 5
 module ActionController #:nodoc:
13 6
   # Caching is a cheap way of speeding up slow applications by keeping the result of calculations, renderings, and database calls
14 7
   # around for subsequent requests. Action Controller affords you three approaches in varying levels of granularity: Page, Action, Fragment.
@@ -31,6 +24,12 @@ module ActionController #:nodoc:
31 24
   #   ActionController::Base.cache_store = :mem_cache_store, "localhost"
32 25
   #   ActionController::Base.cache_store = MyOwnStore.new("parameter")
33 26
   module Caching
  27
+    autoload :Actions, 'action_controller/caching/actions'
  28
+    autoload :Fragments, 'action_controller/caching/fragments'
  29
+    autoload :Pages, 'action_controller/caching/pages'
  30
+    autoload :SqlCache, 'action_controller/caching/sql_cache'
  31
+    autoload :Sweeping, 'action_controller/caching/sweeping'
  32
+
34 33
     def self.included(base) #:nodoc:
35 34
       base.class_eval do
36 35
         @@cache_store = nil
@@ -63,10 +62,9 @@ def cache(key, options = {}, &block)
63 62
         end
64 63
       end
65 64
 
66  
-
67  
-    private    
  65
+    private
68 66
       def cache_configured?
69 67
         self.class.cache_configured?
70 68
       end
71 69
   end
72  
-end
  70
+end
1  actionpack/lib/action_controller/cgi_process.rb
... ...
@@ -1,5 +1,4 @@
1 1
 require 'action_controller/cgi_ext'
2  
-require 'action_controller/session/cookie_store'
3 2
 
4 3
 module ActionController #:nodoc:
5 4
   class Base
4  actionpack/lib/action_controller/integration.rb
... ...
@@ -1,7 +1,3 @@
1  
-require 'action_controller/test_case'
2  
-require 'action_controller/dispatcher'
3  
-require 'action_controller/test_process'
4  
-
5 1
 require 'stringio'
6 2
 require 'uri'
7 3
 
1  actionpack/lib/action_controller/performance_test.rb
... ...
@@ -1,4 +1,3 @@
1  
-require 'action_controller/integration'
2 1
 require 'active_support/testing/performance'
3 2
 require 'active_support/testing/default'
4 3
 
1  actionpack/lib/action_controller/rack_process.rb
... ...
@@ -1,5 +1,4 @@
1 1
 require 'action_controller/cgi_ext'
2  
-require 'action_controller/session/cookie_store'
3 2
 
4 3
 module ActionController #:nodoc:
5 4
   class RackRequest < AbstractRequest #:nodoc:
1  actionpack/lib/action_controller/request_profiler.rb
... ...
@@ -1,5 +1,4 @@
1 1
 require 'optparse'
2  
-require 'action_controller/integration'
3 2
 
4 3
 module ActionController
5 4
   class RequestProfiler
4  actionpack/lib/action_controller/resources.rb
@@ -669,7 +669,3 @@ def action_options_for(action, resource, method = nil)
669 669
       end
670 670
   end
671 671
 end
672  
-
673  
-class ActionController::Routing::RouteSet::Mapper
674  
-  include ActionController::Resources
675  
-end
1  actionpack/lib/action_controller/routing.rb
... ...
@@ -1,6 +1,5 @@
1 1
 require 'cgi'
2 2
 require 'uri'
3  
-require 'action_controller/polymorphic_routes'
4 3
 require 'action_controller/routing/optimisations'
5 4
 require 'action_controller/routing/routing_ext'
6 5
 require 'action_controller/routing/route'
2  actionpack/lib/action_controller/routing/route_set.rb
@@ -7,6 +7,8 @@ class RouteSet #:nodoc:
7 7
       # Mapper instances have relatively few instance methods, in order to avoid
8 8
       # clashes with named routes.
9 9
       class Mapper #:doc:
  10
+        include ActionController::Resources
  11
+
10 12
         def initialize(set) #:nodoc:
11 13
           @set = set
12 14
         end
7  actionpack/lib/action_controller/session_management.rb
... ...
@@ -1,10 +1,3 @@
1  
-require 'action_controller/session/cookie_store'
2  
-require 'action_controller/session/drb_store'
3  
-require 'action_controller/session/mem_cache_store'
4  
-if Object.const_defined?(:ActiveRecord)
5  
-  require 'action_controller/session/active_record_store'
6  
-end
7  
-
8 1
 module ActionController #:nodoc:
9 2
   module SessionManagement #:nodoc:
10 3
     def self.included(base)
2  actionpack/lib/action_view/test_case.rb
... ...
@@ -1,5 +1,3 @@
1  
-require 'action_controller/test_case'
2  
-
3 1
 module ActionView
4 2
   class TestCase < ActiveSupport::TestCase
5 3
     include ActionController::TestCase::Assertions
1  actionpack/test/activerecord/active_record_store_test.rb
... ...
@@ -1,7 +1,6 @@
1 1
 # These tests exercise CGI::Session::ActiveRecordStore, so you're going to
2 2
 # need AR in a sibling directory to AP and have SQLite installed.
3 3
 require 'active_record_unit'
4  
-require 'action_controller/session/active_record_store'
5 4
 
6 5
 module CommonActiveRecordStoreTests
7 6
   def test_basics
1  actionpack/test/controller/cgi_test.rb
... ...
@@ -1,5 +1,4 @@
1 1
 require 'abstract_unit'
2  
-require 'action_controller/cgi_process'
3 2
 
4 3
 class BaseCgiTest < Test::Unit::TestCase
5 4
   def setup
2  actionpack/test/controller/dispatcher_test.rb
@@ -2,8 +2,6 @@
2 2
 
3 3
 uses_mocha 'dispatcher tests' do
4 4
 
5  
-require 'action_controller/dispatcher'
6  
-
7 5
 class DispatcherTest < Test::Unit::TestCase
8 6
   Dispatcher = ActionController::Dispatcher
9 7
 
2  actionpack/test/controller/integration_test.rb
... ...
@@ -1,6 +1,4 @@
1 1
 require 'abstract_unit'
2  
-require 'action_controller/integration'
3  
-require 'action_controller/routing'
4 2
 
5 3
 uses_mocha 'integration' do
6 4
 
2  actionpack/test/controller/integration_upload_test.rb
... ...
@@ -1,6 +1,4 @@
1 1
 require 'abstract_unit'
2  
-require 'action_controller/integration'
3  
-require 'action_controller/routing'
4 2
 
5 3
 unless defined? ApplicationController
6 4
   class ApplicationController < ActionController::Base
1  actionpack/test/controller/rack_test.rb
... ...
@@ -1,5 +1,4 @@
1 1
 require 'abstract_unit'
2  
-require 'action_controller/rack_process'
3 2
 
4 3
 class BaseRackTest < Test::Unit::TestCase
5 4
   def setup
1  actionpack/test/controller/request_test.rb
... ...
@@ -1,5 +1,4 @@
1 1
 require 'abstract_unit'
2  
-require 'action_controller/integration'
3 2
 
4 3
 class RequestTest < ActiveSupport::TestCase
5 4
   def setup
1  actionpack/test/controller/routing_test.rb
... ...
@@ -1,6 +1,5 @@
1 1
 require 'abstract_unit'
2 2
 require 'controller/fake_controllers'
3  
-require 'action_controller/routing'
4 3
 
5 4
 class MilestonesController < ActionController::Base
6 5
   def index() head :ok end
3  actionpack/test/controller/session/cookie_store_test.rb
... ...
@@ -1,7 +1,4 @@
3  actionpack/test/controller/session/mem_cache_store_test.rb
... ...
@@ -1,7 +1,4 @@
1 1
 require 'abstract_unit'
2  
-require 'action_controller/cgi_process'
3  
-require 'action_controller/cgi_ext'
4  
-
5 2
 
6 3
 class CGI::Session
7 4
   def cache

0 notes on commit 31ce92f

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