123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Namespace Children
Classes:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, Enumerable
Inherits: Object
Defined in: lib/rack/multipart/parser.rb

Class Method Summary

Instance Method Summary

Constructor Details

.new(tempfile) ⇒ Collector

[ GitHub ]

  
# File 'lib/rack/multipart/parser.rb', line 157

def initialize(tempfile)
  @tempfile = tempfile
  @mime_parts = []
  @open_files = 0
end

Instance Method Details

#check_file_part_limit (private)

[ GitHub ]

  
# File 'lib/rack/multipart/parser.rb', line 195

def check_file_part_limit
  file_limit = Utils.multipart_file_limit

  if file_limit && file_limit > 0
    if (@open_files + 1) >= file_limit
      @mime_parts.each(&:close)
      raise MultipartPartLimitError, 'Maximum file multiparts in content reached'
    end
  end
end

#check_total_part_limit (private)

[ GitHub ]

  
# File 'lib/rack/multipart/parser.rb', line 206

def check_total_part_limit
  part_limit = Utils.multipart_total_part_limit

  if part_limit && part_limit > 0
    if (@mime_parts.size + 1) >= part_limit
      @mime_parts.each(&:close)
      raise MultipartTotalPartLimitError, 'Maximum total multiparts in content reached'
    end
  end
end

#each

[ GitHub ]

  
# File 'lib/rack/multipart/parser.rb', line 163

def each
  @mime_parts.each { |part| yield part }
end

#on_mime_body(mime_index, content)

[ GitHub ]

  
# File 'lib/rack/multipart/parser.rb', line 186

def on_mime_body(mime_index, content)
  @mime_parts[mime_index].body << content
end

#on_mime_finish(mime_index)

[ GitHub ]

  
# File 'lib/rack/multipart/parser.rb', line 190

def on_mime_finish(mime_index)
end

#on_mime_head(mime_index, head, filename, content_type, name)

[ GitHub ]

  
# File 'lib/rack/multipart/parser.rb', line 167

def on_mime_head(mime_index, head, filename, content_type, name)
  check_total_part_limit

  if filename
    # This will raise an exception if we are at the limit:
    check_file_part_limit

    body = @tempfile.call(filename, content_type)
    body.binmode if body.respond_to?(:binmode)
    klass = TempfilePart
    @open_files += 1
  else
    body = String.new
    klass = BufferPart
  end

  @mime_parts[mime_index] = klass.new(body, head, filename, content_type, name)
end