Class: HTTP::Message::Body::Parts
- Inherits:
-
Object
- Object
- HTTP::Message::Body::Parts
- Defined in:
- lib/httpclient/http.rb
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #add(part) ⇒ Object
-
#initialize ⇒ Parts
constructor
A new instance of Parts.
- #parts ⇒ Object
Constructor Details
#initialize ⇒ Parts
Returns a new instance of Parts.
595 596 597 598 599 |
# File 'lib/httpclient/http.rb', line 595 def initialize @body = [] @size = 0 @as_stream = false end |
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
593 594 595 |
# File 'lib/httpclient/http.rb', line 593 def size @size end |
Instance Method Details
#add(part) ⇒ Object
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 |
# File 'lib/httpclient/http.rb', line 601 def add(part) if Message.file?(part) @as_stream = true @body << part if part.respond_to?(:lstat) @size += part.lstat.size elsif part.respond_to?(:size) if sz = part.size @size += sz else @size = nil end 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 |
#parts ⇒ Object
626 627 628 629 630 631 632 |
# File 'lib/httpclient/http.rb', line 626 def parts if @as_stream @body else [@body.join] end end |