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.
-
#sizes ⇒ Object
readonly
Returns the value of attribute sizes.
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.
610 611 612 613 614 615 |
# File 'lib/httpclient/http.rb', line 610 def initialize @body = [] @sizes = {} @size = 0 # total @as_stream = false end |
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
607 608 609 |
# File 'lib/httpclient/http.rb', line 607 def size @size end |
#sizes ⇒ Object (readonly)
Returns the value of attribute sizes.
608 609 610 |
# File 'lib/httpclient/http.rb', line 608 def sizes @sizes end |
Instance Method Details
#add(part) ⇒ Object
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 |
# File 'lib/httpclient/http.rb', line 617 def add(part) if Message.file?(part) @as_stream = true @body << part if part.respond_to?(:lstat) sz = part.lstat.size add_size(part, sz) elsif part.respond_to?(:size) if sz = part.size add_size(part, sz) else @sizes.clear @size = nil end else # use chunked upload @sizes.clear @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
645 646 647 648 649 650 651 |
# File 'lib/httpclient/http.rb', line 645 def parts if @as_stream @body else [@body.join] end end |