Class: EmailSpy::Message
- Inherits:
-
Object
- Object
- EmailSpy::Message
- Defined in:
- lib/email_spy/message.rb
Instance Attribute Summary collapse
-
#attachments ⇒ Object
readonly
Returns the value of attribute attachments.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
Instance Method Summary collapse
- #body ⇒ Object
- #content_type ⇒ Object
- #encoding ⇒ Object
- #filepath ⇒ Object
- #from ⇒ Object
-
#initialize(location, email, part = nil) ⇒ Message
constructor
A new instance of Message.
- #render ⇒ Object
- #reply_to ⇒ Object
- #template ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(location, email, part = nil) ⇒ Message
Returns a new instance of Message.
6 7 8 |
# File 'lib/email_spy/message.rb', line 6 def initialize(location, email, part = nil) @location, @email, @part, @attachments = location, email, part, [] end |
Instance Attribute Details
#attachments ⇒ Object (readonly)
Returns the value of attribute attachments.
4 5 6 |
# File 'lib/email_spy/message.rb', line 4 def @attachments end |
#email ⇒ Object (readonly)
Returns the value of attribute email.
3 4 5 |
# File 'lib/email_spy/message.rb', line 3 def email @email end |
Instance Method Details
#body ⇒ Object
27 28 29 |
# File 'lib/email_spy/message.rb', line 27 def body @body ||= (@part && @part.body || @email.body).to_s end |
#content_type ⇒ Object
23 24 25 |
# File 'lib/email_spy/message.rb', line 23 def content_type @part && @part.content_type || @email.content_type end |
#encoding ⇒ Object
43 44 45 |
# File 'lib/email_spy/message.rb', line 43 def encoding if body.respond_to? :encoding then body.encoding else "utf-8" end end |
#filepath ⇒ Object
19 20 21 |
# File 'lib/email_spy/message.rb', line 19 def filepath File.join @location, "#{type}.html" end |
#from ⇒ Object
31 32 33 |
# File 'lib/email_spy/message.rb', line 31 def from @from ||= Array(@email.from).join ", " end |
#render ⇒ Object
10 11 12 13 |
# File 'lib/email_spy/message.rb', line 10 def render unless email..empty? create_templates filepath, binding end |
#reply_to ⇒ Object
35 36 37 |
# File 'lib/email_spy/message.rb', line 35 def reply_to @reply_to ||= Array(@email.reply_to).join ", " end |
#template ⇒ Object
15 16 17 |
# File 'lib/email_spy/message.rb', line 15 def template File.read File. File.join("..", "message.html.erb"), __FILE__ end |
#type ⇒ Object
39 40 41 |
# File 'lib/email_spy/message.rb', line 39 def type if content_type =~ /html/ then "rich" else "plain" end end |