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.
534 535 536 537 538 |
# File 'lib/httpclient/http.rb', line 534 def initialize @body = [] @size = 0 @as_stream = false end |
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
532 533 534 |
# File 'lib/httpclient/http.rb', line 532 def size @size end |
Instance Method Details
#add(part) ⇒ Object
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 |
# File 'lib/httpclient/http.rb', line 540 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.size if @size else @body << part.to_s @size += part.to_s.size if @size end end |
#parts ⇒ Object
565 566 567 568 569 570 571 |
# File 'lib/httpclient/http.rb', line 565 def parts if @as_stream @body else [@body.join] end end |