actionmailer 5.0.0.racecar1 → 5.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionmailer might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b59f7347e0a5bf0934ab745667a8ce0b337213c
4
- data.tar.gz: b8a19f1db25bff645c92e6329ed6319a2ea3c2ce
3
+ metadata.gz: 4c66edc530e47491b457fe5bbe6bd663b368c860
4
+ data.tar.gz: 0410986754bdd911c65d0ea400c597560b2fa7dd
5
5
  SHA512:
6
- metadata.gz: 2ecf8daffc78d502a44c30d4ec622980e8efc078b6be837c0886017367b392c4f8026e2d67068b13d683cf63404995a3d2b15c4f5c50a7a227ea508f67e23767
7
- data.tar.gz: 080f85a04a5189483a9f16271396765cc1fdeb16ce35cfa7b9b92c501b980555742da12224326ae907a4ac06039d918afc599b3cd6602a1394203b7b2c03cbe8
6
+ metadata.gz: 7b14aa9dc2a1d810efd1bac5f8f0773b8d9e13faa07489d1c7cb15180d5bc479a48a2fb6d5e8098577ce61066cd0fa00f94db381e18a6320d2eaf79516f81937
7
+ data.tar.gz: d6cd2bde888ec9757f1c113f67feac6aa7605589416ec2ced1bf56af3b6d95c8d8e410ed58ab0b3d601495241006b153b5b685a77a11d00f153893d73ef197f2
@@ -1,3 +1,11 @@
1
+ ## Rails 5.0.0.rc2 (June 22, 2016) ##
2
+
3
+ * Exception handling: use `rescue_from` to handle exceptions raised by
4
+ mailer actions, by message delivery, and by deferred delivery jobs.
5
+
6
+ *Jeremy Daer*
7
+
8
+
1
9
  ## Rails 5.0.0.rc1 (May 06, 2016) ##
2
10
 
3
11
  * No changes.
@@ -5,6 +5,7 @@ require 'active_support/core_ext/hash/except'
5
5
  require 'active_support/core_ext/module/anonymous'
6
6
 
7
7
  require 'action_mailer/log_subscriber'
8
+ require 'action_mailer/rescuable'
8
9
 
9
10
  module ActionMailer
10
11
  # Action Mailer allows you to send email from your application using a mailer model and views.
@@ -419,6 +420,7 @@ module ActionMailer
419
420
  # * <tt>deliver_later_queue_name</tt> - The name of the queue used with <tt>deliver_later</tt>.
420
421
  class Base < AbstractController::Base
421
422
  include DeliveryMethods
423
+ include Rescuable
422
424
  include Previews
423
425
 
424
426
  abstract!
@@ -3,11 +3,32 @@ require 'active_job'
3
3
  module ActionMailer
4
4
  # The <tt>ActionMailer::DeliveryJob</tt> class is used when you
5
5
  # want to send emails outside of the request-response cycle.
6
+ #
7
+ # Exceptions are rescued and handled by the mailer class.
6
8
  class DeliveryJob < ActiveJob::Base # :nodoc:
7
9
  queue_as { ActionMailer::Base.deliver_later_queue_name }
8
10
 
11
+ rescue_from StandardError, with: :handle_exception_with_mailer_class
12
+
9
13
  def perform(mailer, mail_method, delivery_method, *args) #:nodoc:
10
14
  mailer.constantize.public_send(mail_method, *args).send(delivery_method)
11
15
  end
16
+
17
+ private
18
+ # "Deserialize" the mailer class name by hand in case another argument
19
+ # (like a Global ID reference) raised DeserializationError.
20
+ def mailer_class
21
+ if mailer = Array(@serialized_arguments).first || Array(arguments).first
22
+ mailer.constantize
23
+ end
24
+ end
25
+
26
+ def handle_exception_with_mailer_class(exception)
27
+ if klass = mailer_class
28
+ klass.handle_exception exception
29
+ else
30
+ raise exception
31
+ end
32
+ end
12
33
  end
13
34
  end
@@ -8,7 +8,7 @@ module ActionMailer
8
8
  MAJOR = 5
9
9
  MINOR = 0
10
10
  TINY = 0
11
- PRE = "racecar1"
11
+ PRE = "rc2"
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
14
14
  end
@@ -1,7 +1,6 @@
1
1
  require 'delegate'
2
2
 
3
3
  module ActionMailer
4
-
5
4
  # The <tt>ActionMailer::MessageDelivery</tt> class is used by
6
5
  # <tt>ActionMailer::Base</tt> when creating a new mailer.
7
6
  # <tt>MessageDelivery</tt> is a wrapper (+Delegator+ subclass) around a lazy
@@ -14,30 +13,35 @@ module ActionMailer
14
13
  # Notifier.welcome(User.first).deliver_later # enqueue email delivery as a job through Active Job
15
14
  # Notifier.welcome(User.first).message # a Mail::Message object
16
15
  class MessageDelivery < Delegator
17
- def initialize(mailer, mail_method, *args) #:nodoc:
18
- @mailer = mailer
19
- @mail_method = mail_method
20
- @args = args
21
- @obj = nil
16
+ def initialize(mailer_class, action, *args) #:nodoc:
17
+ @mailer_class, @action, @args = mailer_class, action, args
18
+
19
+ # The mail is only processed if we try to call any methods on it.
20
+ # Typical usage will leave it unloaded and call deliver_later.
21
+ @processed_mailer = nil
22
+ @mail_message = nil
22
23
  end
23
24
 
25
+ # Method calls are delegated to the Mail::Message that's ready to deliver.
24
26
  def __getobj__ #:nodoc:
25
- @obj ||= begin
26
- mailer = @mailer.new
27
- mailer.process @mail_method, *@args
28
- mailer.message
29
- end
27
+ @mail_message ||= processed_mailer.message
30
28
  end
31
29
 
32
- def __setobj__(obj) #:nodoc:
33
- @obj = obj
30
+ # Unused except for delegator internals (dup, marshaling).
31
+ def __setobj__(mail_message) #:nodoc:
32
+ @mail_message = mail_message
34
33
  end
35
34
 
36
- # Returns the Mail::Message object
35
+ # Returns the resulting Mail::Message
37
36
  def message
38
37
  __getobj__
39
38
  end
40
39
 
40
+ # Was the delegate loaded, causing the mailer action to be processed?
41
+ def processed?
42
+ @processed_mailer || @mail_message
43
+ end
44
+
41
45
  # Enqueues the email to be delivered through Active Job. When the
42
46
  # job runs it will send the email using +deliver_now!+. That means
43
47
  # that the message will be sent bypassing checking +perform_deliveries+
@@ -78,7 +82,9 @@ module ActionMailer
78
82
  # Notifier.welcome(User.first).deliver_now!
79
83
  #
80
84
  def deliver_now!
81
- message.deliver!
85
+ processed_mailer.handle_exceptions do
86
+ message.deliver!
87
+ end
82
88
  end
83
89
 
84
90
  # Delivers an email:
@@ -86,24 +92,33 @@ module ActionMailer
86
92
  # Notifier.welcome(User.first).deliver_now
87
93
  #
88
94
  def deliver_now
89
- message.deliver
95
+ processed_mailer.handle_exceptions do
96
+ message.deliver
97
+ end
90
98
  end
91
99
 
92
100
  private
101
+ # Returns the processed Mailer instance. We keep this instance
102
+ # on hand so we can delegate exception handling to it.
103
+ def processed_mailer
104
+ @processed_mailer ||= @mailer_class.new.tap do |mailer|
105
+ mailer.process @action, *@args
106
+ end
107
+ end
93
108
 
94
109
  def enqueue_delivery(delivery_method, options={})
95
- if @obj
96
- raise "You've accessed the message before asking to deliver it " \
97
- "later, so you may have made local changes that would be " \
98
- "silently lost if we enqueued a job to deliver it. Why? Only " \
110
+ if processed?
111
+ ::Kernel.raise "You've accessed the message before asking to " \
112
+ "deliver it later, so you may have made local changes that would " \
113
+ "be silently lost if we enqueued a job to deliver it. Why? Only " \
99
114
  "the mailer method *arguments* are passed with the delivery job! " \
100
115
  "Do not access the message in any way if you mean to deliver it " \
101
116
  "later. Workarounds: 1. don't touch the message before calling " \
102
117
  "#deliver_later, 2. only touch the message *within your mailer " \
103
118
  "method*, or 3. use a custom Active Job instead of #deliver_later."
104
119
  else
105
- args = @mailer.name, @mail_method.to_s, delivery_method.to_s, *@args
106
- ActionMailer::DeliveryJob.set(options).perform_later(*args)
120
+ args = @mailer_class.name, @action.to_s, delivery_method.to_s, *@args
121
+ ::ActionMailer::DeliveryJob.set(options).perform_later(*args)
107
122
  end
108
123
  end
109
124
  end
@@ -0,0 +1,27 @@
1
+ module ActionMailer #:nodoc:
2
+ # Provides `rescue_from` for mailers. Wraps mailer action processing,
3
+ # mail job processing, and mail delivery.
4
+ module Rescuable
5
+ extend ActiveSupport::Concern
6
+ include ActiveSupport::Rescuable
7
+
8
+ class_methods do
9
+ def handle_exception(exception) #:nodoc:
10
+ rescue_with_handler(exception) || raise(exception)
11
+ end
12
+ end
13
+
14
+ def handle_exceptions #:nodoc:
15
+ yield
16
+ rescue => exception
17
+ rescue_with_handler(exception) || raise
18
+ end
19
+
20
+ private
21
+ def process(*)
22
+ handle_exceptions do
23
+ super
24
+ end
25
+ end
26
+ end
27
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionmailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0.racecar1
4
+ version: 5.0.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-06 00:00:00.000000000 Z
11
+ date: 2016-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 5.0.0.racecar1
19
+ version: 5.0.0.rc2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 5.0.0.racecar1
26
+ version: 5.0.0.rc2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: actionview
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 5.0.0.racecar1
33
+ version: 5.0.0.rc2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 5.0.0.racecar1
40
+ version: 5.0.0.rc2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activejob
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 5.0.0.racecar1
47
+ version: 5.0.0.rc2
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 5.0.0.racecar1
54
+ version: 5.0.0.rc2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: mail
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -114,6 +114,7 @@ files:
114
114
  - lib/action_mailer/message_delivery.rb
115
115
  - lib/action_mailer/preview.rb
116
116
  - lib/action_mailer/railtie.rb
117
+ - lib/action_mailer/rescuable.rb
117
118
  - lib/action_mailer/test_case.rb
118
119
  - lib/action_mailer/test_helper.rb
119
120
  - lib/action_mailer/version.rb
@@ -142,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
143
  requirements:
143
144
  - none
144
145
  rubyforge_project:
145
- rubygems_version: 2.5.1
146
+ rubygems_version: 2.6.4
146
147
  signing_key:
147
148
  specification_version: 4
148
149
  summary: Email composition, delivery, and receiving framework (part of Rails).