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



71
72
73
74
75
76
77
78
# File 'lib/vagrant/util/mime.rb', line 71

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



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

def content
  @content
end

#content_typeString (readonly)

Returns type of the entity content.

Returns:

  • (String)

    type of the entity content



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

def content_type
  @content_type
end

#dispositionString

Returns content disposition.

Returns:

  • (String)

    content disposition



67
68
69
# File 'lib/vagrant/util/mime.rb', line 67

def disposition
  @disposition
end

Instance Method Details

#to_sString

Output MimeEntity as a string

Returns:

  • (String)

    mime data



83
84
85
86
87
88
89
90
91
# File 'lib/vagrant/util/mime.rb', line 83

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