Class: Vagrant::Util::Mime::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/util/mime.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, content_type) ⇒ Entity

Returns a new instance of Entity.

Parameters:

  • entity (String)

    content

  • type (String)

    of the entity content


68
69
70
71
72
73
74
75
# File 'lib/vagrant/util/mime.rb', line 68

def initialize(content, content_type)
  if !MIME::Types.include?(content_type)
    MIME::Types.add(MIME::Type.new(content_type))
  end
  @content = content
  @content_type = MIME::Types[content_type].first
  @content_id = "#{Time.now.to_i}@#{SecureRandom.alphanumeric(24)}.local"
end

Instance Attribute Details

#contentString (readonly)

Returns entity content.

Returns:

  • (String)

    entity content


58
59
60
# File 'lib/vagrant/util/mime.rb', line 58

def content
  @content
end

#content_typeString (readonly)

Returns type of the entity content.

Returns:

  • (String)

    type of the entity content


61
62
63
# File 'lib/vagrant/util/mime.rb', line 61

def content_type
  @content_type
end

#dispositionString

Returns content disposition.

Returns:

  • (String)

    content disposition


64
65
66
# File 'lib/vagrant/util/mime.rb', line 64

def disposition
  @disposition
end

Instance Method Details

#to_sString

Output MimeEntity as a string

Returns:

  • (String)

    mime data


80
81
82
83
84
85
86
87
88
# File 'lib/vagrant/util/mime.rb', line 80

def to_s
  output_string = "Content-ID: <#{@content_id}>\n"
  output_string += "Content-Type: #{@content_type}\n"
  if disposition
    output_string += "Content-Disposition: #{@disposition}\n"
  end
  output_string += "\n#{content}"
  output_string
end