Class: MailBuilder::Attachment

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_builder/attachment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, name, type, headers) ⇒ Attachment

Returns a new instance of Attachment.



6
7
8
9
10
11
12
13
14
# File 'lib/mail_builder/attachment.rb', line 6

def initialize(file, name, type, headers)
  @file = file
  @name = name
  @type = type
  @headers = headers

  # If we have a File/IO object, read it. Otherwise, we'll read it lazily.
  @body = file.read() if !file.kind_of?(Pathname) && file.respond_to?(:read)
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



4
5
6
# File 'lib/mail_builder/attachment.rb', line 4

def file
  @file
end

#headersObject

Returns the value of attribute headers.



4
5
6
# File 'lib/mail_builder/attachment.rb', line 4

def headers
  @headers
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/mail_builder/attachment.rb', line 4

def name
  @name
end

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/mail_builder/attachment.rb', line 4

def type
  @type
end

Instance Method Details

#inspectObject



30
31
32
# File 'lib/mail_builder/attachment.rb', line 30

def inspect
  "#<MailBuilder::Attachment @file=#{@file.inspect}> @name=#{@name.inspect} @type=#{@type.inspect} @headers=#{@headers.inspect}"
end

#to_sObject



16
17
18
19
20
# File 'lib/mail_builder/attachment.rb', line 16

def to_s
  @body ||= File.open(file.to_s(), "rb") { |f| f.read() }

  [@body].pack("m")
end