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


78
79
80
# File 'lib/rack/multipart/parser.rb', line 78

def body
  @body
end

#content_typeObject

Returns the value of attribute content_type


78
79
80
# File 'lib/rack/multipart/parser.rb', line 78

def content_type
  @content_type
end

#filenameObject

Returns the value of attribute filename


78
79
80
# File 'lib/rack/multipart/parser.rb', line 78

def filename
  @filename
end

#headObject

Returns the value of attribute head


78
79
80
# File 'lib/rack/multipart/parser.rb', line 78

def head
  @head
end

#nameObject

Returns the value of attribute name


78
79
80
# File 'lib/rack/multipart/parser.rb', line 78

def name
  @name
end

Instance Method Details

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

Yields:

  • (data)

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/rack/multipart/parser.rb', line 79

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}
  elsif !filename && content_type && body.is_a?(IO)
    body.rewind

    # Generic multipart cases, not coming from a form
    data = {:type => content_type,
            :name => name, :tempfile => body, :head => head}
  end

  yield data
end