| Class | Mack::Notifier::Attachment |
| In: |
lib/mack-notifier/attachment.rb
|
| Parent: | Object |
Creates an attachment for a Mack::Notifier object.
| body | [RW] | Returns a String representing the body of the attachment. This String is NOT encoded in anyway! |
| file_name | [RW] | Returns the name of the attached file. |
# File lib/mack-notifier/attachment.rb, line 11
11: def initialize(body = nil)
12: unless body.nil?
13: self.add_file(body) if body.is_a?(String)
14: self.add_io(body) if body.is_a?(IO)
15: self.add_uploaded_file(body) if body.is_a?(Mack::Request::UploadedFile)
16: end
17: end
Takes a path to a file, reads it in, and sets the file_name based on the path.
# File lib/mack-notifier/attachment.rb, line 25
25: def add_file(file)
26: self.file_name = File.basename(file)
27: self.body = File.read(file)
28: end
Takes an IO object and sets the body. You‘ll need to explicity set the file_name afterwards.
# File lib/mack-notifier/attachment.rb, line 20
20: def add_io(io)
21: self.body = io.read
22: end