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

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/multipart/parser.rb

Defined Under Namespace

Classes: BufferPart, MimePart, TempfilePart

Instance Method Summary collapse

Methods included from Enumerable

#as_json, #compact_blank, #exclude?, #excluding, #in_order_of, #including, #index_by, #index_with, #many?, #maximum, #minimum, #pick, #pluck, #sole, #sum

Constructor Details

#initialize(tempfile) ⇒ Collector

Returns a new instance of Collector.



120
121
122
123
124
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/multipart/parser.rb', line 120

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

Instance Method Details

#eachObject



126
127
128
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/multipart/parser.rb', line 126

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

#on_mime_body(mime_index, content) ⇒ Object



146
147
148
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/multipart/parser.rb', line 146

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

#on_mime_finish(mime_index) ⇒ Object



150
151
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/multipart/parser.rb', line 150

def on_mime_finish(mime_index)
end

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



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rack-2.2.5/lib/rack/multipart/parser.rb', line 130

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_open_files
end