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.



541
542
543
544
545
# File 'lib/httpclient/http.rb', line 541

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

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.



539
540
541
# File 'lib/httpclient/http.rb', line 539

def size
  @size
end

Instance Method Details

#add(part) ⇒ Object



547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
# File 'lib/httpclient/http.rb', line 547

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.bytesize if @size
  else
    @body << part.to_s
    @size += part.to_s.bytesize if @size
  end
end

#partsObject



572
573
574
575
576
577
578
# File 'lib/httpclient/http.rb', line 572

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