Class: Howitzer::Email
- Inherits:
-
Object
- Object
- Howitzer::Email
- Includes:
- RSpec::Matchers
- Defined in:
- lib/howitzer/email.rb
Overview
This class describes single email
Class Attribute Summary collapse
-
.adapter_name ⇒ Object
readonly
Returns the value of attribute adapter_name.
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Class Method Summary collapse
-
.adapter ⇒ <MailAdapters::Abstract>
A mail adapter class.
-
.adapter=(adapter_name) ⇒ Object
Specifies a mail adapter.
-
.find_by_recipient(recipient, params = {}) ⇒ Email
Searches a mail by a recepient.
-
.subject(value) ⇒ Object
DSL method to specify a subject pattern directly in an email class.
-
.wait_time(value) ⇒ Object
DSL method to specify a custom wait email time directly in an email class.
Instance Method Summary collapse
-
#html_body ⇒ String?
A html body of the email message.
-
#initialize(message) ⇒ Email
constructor
A new instance of Email.
-
#mail_from ⇒ String
Who has sent the email data in format: User Name <user@email>.
-
#mime_part ⇒ Object
Allows to get email MIME attachment.
-
#plain_text_body ⇒ String?
A plain text of the email message.
-
#received_time ⇒ String
Email received time.
-
#recipients ⇒ Array<String>
Array of recipients who has received current email.
-
#sender_email ⇒ String
A sender user email.
-
#text ⇒ String?
A mail text.
Constructor Details
#initialize(message) ⇒ Email
Returns a new instance of Email.
87 88 89 |
# File 'lib/howitzer/email.rb', line 87 def initialize() @message = end |
Class Attribute Details
.adapter_name ⇒ Object (readonly)
Returns the value of attribute adapter_name.
20 21 22 |
# File 'lib/howitzer/email.rb', line 20 def adapter_name @adapter_name end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
9 10 11 |
# File 'lib/howitzer/email.rb', line 9 def @message end |
Class Method Details
.adapter ⇒ <MailAdapters::Abstract>
Returns a mail adapter class.
13 14 15 16 17 |
# File 'lib/howitzer/email.rb', line 13 def self.adapter return @adapter if @adapter self.adapter = Howitzer.mail_adapter.to_sym @adapter end |
.adapter=(adapter_name) ⇒ Object
Specifies a mail adapter
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/howitzer/email.rb', line 60 def self.adapter=(adapter_name) @adapter_name = adapter_name case adapter_name when Symbol, String require "howitzer/mail_adapters/#{adapter_name}" @adapter = MailAdapters.const_get(adapter_name.to_s.capitalize.to_s) else raise Howitzer::NoMailAdapterError end end |
.find_by_recipient(recipient, params = {}) ⇒ Email
Searches a mail by a recepient
78 79 80 81 82 83 84 85 |
# File 'lib/howitzer/email.rb', line 78 def self.find_by_recipient(recipient, params = {}) if defined?(subject_value).nil? || subject_value.nil? raise Howitzer::NoEmailSubjectError, "Please specify email subject. For example:\n" \ "class SomeEmail < Howitzer::Email\n" \ " subject ‘some subject text’\nend" end new(adapter.find(recipient, (params), wait: wait_time_value)) end |
.subject(value) ⇒ Object
DSL method to specify a subject pattern directly in an email class
34 35 36 37 |
# File 'lib/howitzer/email.rb', line 34 def subject(value) define_singleton_method(:subject_value) { value } private_class_method :subject_value end |
.wait_time(value) ⇒ Object
DSL method to specify a custom wait email time directly in an email class
48 49 50 51 |
# File 'lib/howitzer/email.rb', line 48 def wait_time(value) define_singleton_method(:wait_time_value) { value } private_class_method :wait_time_value end |
Instance Method Details
#html_body ⇒ String?
Returns a html body of the email message.
99 100 101 |
# File 'lib/howitzer/email.rb', line 99 def html_body .html_body end |
#mail_from ⇒ String
Returns who has sent the email data in format: User Name <user@email>.
111 112 113 |
# File 'lib/howitzer/email.rb', line 111 def mail_from .mail_from end |
#mime_part ⇒ Object
Allows to get email MIME attachment
135 136 137 |
# File 'lib/howitzer/email.rb', line 135 def mime_part .mime_part end |
#plain_text_body ⇒ String?
Returns a plain text of the email message.
93 94 95 |
# File 'lib/howitzer/email.rb', line 93 def plain_text_body .plain_text_body end |
#received_time ⇒ String
Returns email received time.
123 124 125 |
# File 'lib/howitzer/email.rb', line 123 def received_time .received_time end |
#recipients ⇒ Array<String>
Returns array of recipients who has received current email.
117 118 119 |
# File 'lib/howitzer/email.rb', line 117 def recipients .recipients end |
#sender_email ⇒ String
Returns a sender user email.
129 130 131 |
# File 'lib/howitzer/email.rb', line 129 def sender_email .sender_email end |
#text ⇒ String?
Returns a mail text.
105 106 107 |
# File 'lib/howitzer/email.rb', line 105 def text .text end |