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.



546
547
548
549
550
# File 'lib/httpclient/http.rb', line 546

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

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.



544
545
546
# File 'lib/httpclient/http.rb', line 544

def size
  @size
end

Instance Method Details

#add(part) ⇒ Object



552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
# File 'lib/httpclient/http.rb', line 552

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



577
578
579
580
581
582
583
# File 'lib/httpclient/http.rb', line 577

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