Class: HTTP::Message::Body::Parts

Inherits:
Object
  • Object
show all
Defined in:
lib/httpclient/http.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParts

Returns a new instance of Parts.



517
518
519
520
521
# File 'lib/httpclient/http.rb', line 517

def initialize
  @body = []
  @size = 0
  @as_stream = false
end

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.



515
516
517
# File 'lib/httpclient/http.rb', line 515

def size
  @size
end

Instance Method Details

#add(part) ⇒ Object



523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
# File 'lib/httpclient/http.rb', line 523

def add(part)
  if Message.file?(part)
    @as_stream = true
    @body << part
    if part.respond_to?(:size)
      if sz = part.size
        @size += sz
      else
        @size = nil
      end
    elsif part.respond_to?(:lstat)
      @size += part.lstat.size
    else
      # use chunked upload
      @size = nil
    end
  elsif @body[-1].is_a?(String)
    @body[-1] += part.to_s
    @size += part.to_s.size if @size
  else
    @body << part.to_s
    @size += part.to_s.size if @size
  end
end

#partsObject



548
549
550
551
552
553
554
# File 'lib/httpclient/http.rb', line 548

def parts
  if @as_stream
    @body
  else
    [@body.join]
  end
end