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 143

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

Instance Method Details

#check_part_limits (private)

[ GitHub ]

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

def check_part_limits
  file_limit = Utils.multipart_file_limit
  part_limit = Utils.multipart_total_part_limit

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

  if part_limit && part_limit > 0
    if @mime_parts.size >= 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 149

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

#on_mime_body(mime_index, content)

[ GitHub ]

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

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 173

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 153

def on_mime_head(mime_index, head, filename, content_type, name)
  if filename
    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)

  check_part_limits
end