Class Mack::Notifier::Attachment
In: lib/mack-notifier/attachment.rb
Parent: Object

Creates an attachment for a Mack::Notifier object.

Methods

Attributes

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.

Public Class methods

[Source]

    # 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

Public Instance methods

Takes a path to a file, reads it in, and sets the file_name based on the path.

[Source]

    # 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.

[Source]

    # File lib/mack-notifier/attachment.rb, line 20
20:       def add_io(io)
21:         self.body = io.read
22:       end

Takes a Mack::Request::UploadedFile file object, reads it in, and sets the file name.

[Source]

    # File lib/mack-notifier/attachment.rb, line 31
31:       def add_uploaded_file(file)
32:         self.body = File.read(file.temp_file.path)
33:         self.file_name = file.file_name
34:       end

[Validate]