Class: Hanami::Mailer::Delivery::Result
- Inherits:
-
Object
- Object
- Hanami::Mailer::Delivery::Result
- Defined in:
- lib/hanami/mailer/delivery/result.rb
Overview
Represents the outcome of a message delivery attempt.
This is the base class for delivery results. Delivery methods return an instance of this class (or a subclass) from their #call method. Third-party delivery methods are encouraged to subclass this and add any service-specific attributes they need.
Instance Attribute Summary collapse
-
#error ⇒ #to_s?
readonly
The error that occurred during delivery, if delivery failed.
-
#message ⇒ Hanami::Mailer::Message
readonly
The prepared message that was (or was attempted to be) delivered.
-
#response ⇒ Object?
readonly
The raw return value from the delivery method, if any.
Instance Method Summary collapse
-
#failure? ⇒ Boolean
Returns true if delivery failed.
-
#initialize(message:, response: nil, error: nil) ⇒ Result
constructor
private
A new instance of Result.
-
#success? ⇒ Boolean
Returns true if delivery succeeded.
Constructor Details
#initialize(message:, response: nil, error: nil) ⇒ Result
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Result.
73 74 75 76 77 |
# File 'lib/hanami/mailer/delivery/result.rb', line 73 def initialize(message:, response: nil, error: nil) @message = @response = response @error = error end |
Instance Attribute Details
#error ⇒ #to_s? (readonly)
The error that occurred during delivery, if delivery failed.
This is nil for a successful delivery. For a failed delivery it is a truthy object
describing the error. For SMTP deliveries, this will be an exception raised during
delivery, but delivery methods are free to represent failures with any object that
responds to #to_s, allowing for objects that carry richer error details.
65 66 67 |
# File 'lib/hanami/mailer/delivery/result.rb', line 65 def error @error end |
#message ⇒ Hanami::Mailer::Message (readonly)
The prepared message that was (or was attempted to be) delivered.
40 41 42 |
# File 'lib/hanami/mailer/delivery/result.rb', line 40 def @message end |
#response ⇒ Object? (readonly)
The raw return value from the delivery method, if any.
For SMTP delivery this will be the Mail::Message object. For test delivery this will be nil. The exact type is delivery-method-specific; consult the documentation for the delivery method you are using.
52 53 54 |
# File 'lib/hanami/mailer/delivery/result.rb', line 52 def response @response end |
Instance Method Details
#failure? ⇒ Boolean
Returns true if delivery failed.
95 96 97 |
# File 'lib/hanami/mailer/delivery/result.rb', line 95 def failure? !success? end |
#success? ⇒ Boolean
Returns true if delivery succeeded.
85 86 87 |
# File 'lib/hanami/mailer/delivery/result.rb', line 85 def success? error.nil? end |