Class: Vagrant::Util::Mime::Multipart
- Inherits:
-
Object
- Object
- Vagrant::Util::Mime::Multipart
- Defined in:
- lib/vagrant/util/mime.rb
Instance Attribute Summary collapse
-
#content ⇒ Array<String>
Collection of content part of the multipart mime.
-
#content_type ⇒ String
Type of the content.
-
#headers ⇒ Hash
Headers for the mime.
Instance Method Summary collapse
-
#add(entry) ⇒ Object
Add an entry to the multipart mime.
-
#initialize(content_type = "multipart/mixed") ⇒ Multipart
constructor
A new instance of Multipart.
-
#to_s ⇒ String
Output MimeEntity as a string.
Constructor Details
#initialize(content_type = "multipart/mixed") ⇒ Multipart
Returns a new instance of Multipart.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/vagrant/util/mime.rb', line 20 def initialize(content_type="multipart/mixed") @content_id = "#{Time.now.to_i}@#{SecureRandom.alphanumeric(24)}.local" @boundary = "Boundary_#{SecureRandom.alphanumeric(24)}" @content_type = MIME::Types[content_type].first @content = [] @headers = { "Content-ID"=> "<#{@content_id}>", "Content-Type"=> "#{content_type}; boundary=#{@boundary}", } end |
Instance Attribute Details
#content ⇒ Array<String>
Returns collection of content part of the multipart mime.
10 11 12 |
# File 'lib/vagrant/util/mime.rb', line 10 def content @content end |
#content_type ⇒ String
Returns type of the content.
13 14 15 |
# File 'lib/vagrant/util/mime.rb', line 13 def content_type @content_type end |
#headers ⇒ Hash
Returns headers for the mime.
16 17 18 |
# File 'lib/vagrant/util/mime.rb', line 16 def headers @headers end |
Instance Method Details
#add(entry) ⇒ Object
Add an entry to the multipart mime
34 35 36 |
# File 'lib/vagrant/util/mime.rb', line 34 def add(entry) content << entry end |
#to_s ⇒ String
Output MimeEntity as a string
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/vagrant/util/mime.rb', line 41 def to_s output_string = "" headers.each do |k, v| output_string += "#{k}: #{v}\n" end output_string += "\n--#{@boundary}\n" @content.each do |entry| output_string += entry.to_s output_string += "\n--#{@boundary}\n" end output_string end |