Class: Protocol::HTTP::Body::Streamable
- Defined in:
- lib/protocol/http/body/streamable.rb
Overview
Invokes a callback once the body has finished reading.
Instance Attribute Summary
Attributes inherited from Wrapper
Class Method Summary collapse
Instance Method Summary collapse
- #close(error = nil) ⇒ Object
- #finish ⇒ Object
-
#initialize(body, callback) ⇒ Streamable
constructor
A new instance of Streamable.
Methods inherited from Wrapper
#empty?, #inspect, #length, #read
Methods inherited from Readable
#each, #empty?, #join, #length, #read
Constructor Details
#initialize(body, callback) ⇒ Streamable
Returns a new instance of Streamable.
38 39 40 41 42 |
# File 'lib/protocol/http/body/streamable.rb', line 38 def initialize(body, callback) super(body) @callback = callback end |
Class Method Details
.wrap(message, &block) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/protocol/http/body/streamable.rb', line 30 def self.wrap(, &block) if body = &.body and !body.empty? .body = self.new(.body, block) else yield end end |
Instance Method Details
#close(error = nil) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/protocol/http/body/streamable.rb', line 56 def close(error = nil) if @body super @callback.call(error) @body = nil end end |
#finish ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/protocol/http/body/streamable.rb', line 44 def finish if @body result = super @callback.call @body = nil return result end end |