Class: Rack::Multipart::Parser::Collector::MimePart

Inherits:
Struct
  • Object
show all
Defined in:
lib/rack/multipart/parser.rb

Direct Known Subclasses

BufferPart, TempfilePart

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



108
109
110
# File 'lib/rack/multipart/parser.rb', line 108

def body
  @body
end

#content_typeObject

Returns the value of attribute content_type

Returns:

  • (Object)

    the current value of content_type



108
109
110
# File 'lib/rack/multipart/parser.rb', line 108

def content_type
  @content_type
end

#filenameObject

Returns the value of attribute filename

Returns:

  • (Object)

    the current value of filename



108
109
110
# File 'lib/rack/multipart/parser.rb', line 108

def filename
  @filename
end

#headObject

Returns the value of attribute head

Returns:

  • (Object)

    the current value of head



108
109
110
# File 'lib/rack/multipart/parser.rb', line 108

def head
  @head
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



108
109
110
# File 'lib/rack/multipart/parser.rb', line 108

def name
  @name
end

Instance Method Details

#get_data {|data| ... } ⇒ Object

Yields:

  • (data)


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/rack/multipart/parser.rb', line 109

def get_data
  data = body
  if filename == ""
    # filename is blank which means no file has been selected
    return
  elsif filename
    body.rewind if body.respond_to?(:rewind)

    # Take the basename of the upload's original filename.
    # This handles the full Windows paths given by Internet Explorer
    # (and perhaps other broken user agents) without affecting
    # those which give the lone filename.
    fn = filename.split(/[\/\\]/).last

    data = { filename: fn, type: content_type,
            name: name, tempfile: body, head: head }
  end

  yield data
end