public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
use autoload instead of explicit requires for ActionMailer
josh (author)
Sun Nov 23 10:27:25 -0800 2008
commit  e201fc750bf4b7dff1875b7fcdd47f1686ef2052
tree    ced60e6ae52de148c8c0a7673dc65a73b03d1c4f
parent  04d2d043ca9c59ab93522f1d8c0810cf47f05b23
...
31
32
33
34
35
36
37
38
39
40
41
 
 
 
 
42
43
 
 
 
 
 
 
 
 
 
 
44
45
46
47
 
 
 
48
49
 
 
50
51
52
 
 
 
 
 
...
31
32
33
 
 
 
 
 
 
 
 
34
35
36
37
38
 
39
40
41
42
43
44
45
46
47
48
49
 
 
 
50
51
52
53
 
54
55
56
57
 
58
59
60
61
62
0
@@ -31,22 +31,32 @@ rescue LoadError
0
   end
0
 end
0
 
0
-require 'action_mailer/vendor'
0
-require 'tmail'
0
-
0
-require 'action_mailer/base'
0
-require 'action_mailer/helpers'
0
-require 'action_mailer/mail_helper'
0
-require 'action_mailer/quoting'
0
-require 'action_mailer/test_helper'
0
+module ActionMailer
0
+  def self.load_all!
0
+    [Base, Part, ::Text::Format, ::Net::SMTP]
0
+  end
0
 
0
-require 'net/smtp'
0
+  autoload :AdvAttrAccessor, 'action_mailer/adv_attr_accessor'
0
+  autoload :Base, 'action_mailer/base'
0
+  autoload :Helpers, 'action_mailer/helpers'
0
+  autoload :Part, 'action_mailer/part'
0
+  autoload :PartContainer, 'action_mailer/part_container'
0
+  autoload :Quoting, 'action_mailer/quoting'
0
+  autoload :TestCase, 'action_mailer/test_case'
0
+  autoload :TestHelper, 'action_mailer/test_helper'
0
+  autoload :Utils, 'action_mailer/utils'
0
+end
0
 
0
-ActionMailer::Base.class_eval do
0
-  include ActionMailer::Quoting
0
-  include ActionMailer::Helpers
0
+module Text
0
+  autoload :Format, 'action_mailer/vendor/text_format'
0
+end
0
 
0
-  helper MailHelper
0
+module Net
0
+  autoload :SMTP, 'net/smtp'
0
 end
0
 
0
-silence_warnings { TMail::Encoder.const_set("MAX_LINE_LEN", 200) }
0
+autoload :MailHelper, 'action_mailer/mail_helper'
0
+autoload :TMail, 'action_mailer/vendor/tmail'
0
+
0
+# TODO: Don't explicitly load entire lib
0
+ActionMailer.load_all!
...
1
2
3
4
5
6
7
...
245
246
247
248
 
249
250
251
...
648
649
650
651
 
652
653
654
655
 
656
657
658
...
698
699
700
 
 
 
 
 
701
...
 
 
 
 
1
2
3
...
241
242
243
 
244
245
246
247
...
644
645
646
 
647
648
649
650
 
651
652
653
654
...
694
695
696
697
698
699
700
701
702
0
@@ -1,7 +1,3 @@
0
-require 'action_mailer/adv_attr_accessor'
0
-require 'action_mailer/part'
0
-require 'action_mailer/part_container'
0
-require 'action_mailer/utils'
0
 require 'tmail/net'
0
 
0
 module ActionMailer #:nodoc:
0
@@ -245,7 +241,7 @@ module ActionMailer #:nodoc:
0
   #   and appear last in the mime encoded message. You can also pick a different order from inside a method with
0
   #   +implicit_parts_order+.
0
   class Base
0
-    include AdvAttrAccessor, PartContainer
0
+    include AdvAttrAccessor, PartContainer, Quoting, Utils
0
     if Object.const_defined?(:ActionController)
0
       include ActionController::UrlWriter
0
       include ActionController::Layout
0
@@ -648,11 +644,11 @@ module ActionMailer #:nodoc:
0
 
0
         if @parts.empty?
0
           m.set_content_type(real_content_type, nil, ctype_attrs)
0
-          m.body = Utils.normalize_new_lines(body)
0
+          m.body = normalize_new_lines(body)
0
         else
0
           if String === body
0
             part = TMail::Mail.new
0
-            part.body = Utils.normalize_new_lines(body)
0
+            part.body = normalize_new_lines(body)
0
             part.set_content_type(real_content_type, nil, ctype_attrs)
0
             part.set_content_disposition "inline"
0
             m.parts << part
0
@@ -698,4 +694,9 @@ module ActionMailer #:nodoc:
0
         deliveries << mail
0
       end
0
   end
0
+
0
+  Base.class_eval do
0
+    include Helpers
0
+    helper MailHelper
0
+  end
0
 end
...
1
2
3
4
5
...
 
 
1
2
3
0
@@ -1,5 +1,3 @@
0
-require 'text/format'
0
-
0
 module MailHelper
0
   # Uses Text::Format to take the text and format it, indented two spaces for
0
   # each line, and wrapped at 72 columns.
...
1
2
3
4
5
6
7
8
9
10
11
12
 
13
14
15
...
64
65
66
67
 
68
69
70
...
102
103
104
105
106
107
108
...
 
 
 
 
1
2
3
4
5
6
 
 
7
8
9
10
...
59
60
61
 
62
63
64
65
...
97
98
99
 
100
101
102
0
@@ -1,15 +1,10 @@
0
-require 'action_mailer/adv_attr_accessor'
0
-require 'action_mailer/part_container'
0
-require 'action_mailer/utils'
0
-
0
 module ActionMailer
0
   # Represents a subpart of an email message. It shares many similar
0
   # attributes of ActionMailer::Base.  Although you can create parts manually
0
   # and add them to the +parts+ list of the mailer, it is easier
0
   # to use the helper methods in ActionMailer::PartContainer.
0
   class Part
0
-    include ActionMailer::AdvAttrAccessor
0
-    include ActionMailer::PartContainer
0
+    include AdvAttrAccessor, PartContainer, Utils
0
 
0
     # Represents the body of the part, as a string. This should not be a
0
     # Hash (like ActionMailer::Base), but if you want a template to be rendered
0
@@ -64,7 +59,7 @@ module ActionMailer
0
           when "base64" then
0
             part.body = TMail::Base64.folding_encode(body)
0
           when "quoted-printable"
0
-            part.body = [Utils.normalize_new_lines(body)].pack("M*")
0
+            part.body = [normalize_new_lines(body)].pack("M*")
0
           else
0
             part.body = body
0
         end
0
@@ -102,7 +97,6 @@ module ActionMailer
0
     end
0
 
0
     private
0
-
0
       def squish(values={})
0
         values.delete_if { |k,v| v.nil? }
0
       end
...
10
11
12
13
 
14
15
16
...
10
11
12
 
13
14
15
16
0
@@ -10,7 +10,7 @@ module ActionMailer
0
   end
0
 
0
   class TestCase < ActiveSupport::TestCase
0
-    include ActionMailer::Quoting
0
+    include Quoting, TestHelper
0
 
0
     setup :initialize_test_deliveries
0
     setup :set_expected_mail
...
58
59
60
 
61
62
63
...
58
59
60
61
62
63
64
0
@@ -58,6 +58,7 @@ module ActionMailer
0
   end
0
 end
0
 
0
+# TODO: Deprecate this
0
 module Test
0
   module Unit
0
     class TestCase
...
3
4
5
6
7
8
...
3
4
5
 
6
7
0
@@ -3,6 +3,5 @@ module ActionMailer
0
     def normalize_new_lines(text)
0
       text.to_s.gsub(/\r\n?/, "\n")
0
     end
0
-    module_function :normalize_new_lines
0
   end
0
 end

Comments

whatcould Sun Nov 23 12:05:02 -0800 2008

Had to comment out “require ‘tmail/net’ in actionmailer/base.rb” to get rails to start after this commit.

methodmissing Sun Nov 23 12:24:55 -0800 2008

same here

josh Sun Nov 23 13:00:03 -0800 2008

hmm, can’t seem to reproduce the issue. what exception is getting raised?

whatcould Sun Nov 23 14:06:28 -0800 2008
  1. no such file to load—tmail/net (RuntimeError)

ActionMailer seems to work without it, interestingly enough.

josh Sun Nov 23 14:39:14 -0800 2008

Jeremy just remove the line a few mins ago. It should be fine for now.