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.
546 547 548 549 550 |
# File 'lib/httpclient/http.rb', line 546 def initialize @body = [] @size = 0 @as_stream = false end |
Instance Attribute Details
#size ⇒ Object (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 |
#parts ⇒ Object
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 |