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.
88 89 90 |
# File 'lib/howitzer/email.rb', line 88 def initialize() @message = end |
Class Attribute Details
.adapter_name ⇒ Object (readonly)
Returns the value of attribute adapter_name.
21 22 23 |
# File 'lib/howitzer/email.rb', line 21 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 18 |
# 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
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/howitzer/email.rb', line 61 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
79 80 81 82 83 84 85 86 |
# File 'lib/howitzer/email.rb', line 79 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
35 36 37 38 |
# File 'lib/howitzer/email.rb', line 35 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
49 50 51 52 |
# File 'lib/howitzer/email.rb', line 49 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.
100 101 102 |
# File 'lib/howitzer/email.rb', line 100 def html_body .html_body end |
#mail_from ⇒ String
Returns who has sent the email data in format: User Name <user@email>.
112 113 114 |
# File 'lib/howitzer/email.rb', line 112 def mail_from .mail_from end |
#mime_part ⇒ Object
Allows to get email MIME attachment
136 137 138 |
# File 'lib/howitzer/email.rb', line 136 def mime_part .mime_part end |
#plain_text_body ⇒ String?
Returns a plain text of the email message.
94 95 96 |
# File 'lib/howitzer/email.rb', line 94 def plain_text_body .plain_text_body end |
#received_time ⇒ String
Returns email received time.
124 125 126 |
# File 'lib/howitzer/email.rb', line 124 def received_time .received_time end |
#recipients ⇒ Array<String>
Returns array of recipients who has received current email.
118 119 120 |
# File 'lib/howitzer/email.rb', line 118 def recipients .recipients end |
#sender_email ⇒ String
Returns a sender user email.
130 131 132 |
# File 'lib/howitzer/email.rb', line 130 def sender_email .sender_email end |
#text ⇒ String?
Returns a mail text.
106 107 108 |
# File 'lib/howitzer/email.rb', line 106 def text .text end |