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.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/vagrant/util/mime.rb', line 23 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.
13 14 15 |
# File 'lib/vagrant/util/mime.rb', line 13 def content @content end |
#content_type ⇒ String
Returns type of the content.
16 17 18 |
# File 'lib/vagrant/util/mime.rb', line 16 def content_type @content_type end |
#headers ⇒ Hash
Returns headers for the mime.
19 20 21 |
# File 'lib/vagrant/util/mime.rb', line 19 def headers @headers end |
Instance Method Details
#add(entry) ⇒ Object
Add an entry to the multipart mime
37 38 39 |
# File 'lib/vagrant/util/mime.rb', line 37 def add(entry) content << entry end |
#to_s ⇒ String
Output MimeEntity as a string
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/vagrant/util/mime.rb', line 44 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 |