Class: Protocol::HTTP::Body::Wrapper
- Defined in:
- lib/protocol/http/body/wrapper.rb
Overview
Wrapping body instance. Typically you’d override ‘#read`.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
Class Method Summary collapse
-
.wrap(message) ⇒ Object
Wrap the body of the given message in a new instance of this class.
Instance Method Summary collapse
-
#as_json ⇒ Object
Convert the body to a hash suitable for serialization.
-
#buffered ⇒ Object
Forwards to the wrapped body.
-
#close(error = nil) ⇒ Object
Close the body.
-
#discard ⇒ Object
Forwards to the wrapped body.
-
#empty? ⇒ Boolean
Forwards to the wrapped body.
-
#initialize(body) ⇒ Wrapper
constructor
Initialize the wrapper with the given body.
-
#inspect ⇒ Object
Inspect the wrapped body.
-
#length ⇒ Object
Forwards to the wrapped body.
-
#read ⇒ Object
Forwards to the wrapped body.
-
#ready? ⇒ Boolean
Forwards to the wrapped body.
-
#rewind ⇒ Object
Forwards to the wrapped body.
-
#rewindable? ⇒ Boolean
Forwards to the wrapped body.
- #The wrapped body.=(wrappedbody. = (value)) ⇒ Object
-
#to_json ⇒ Object
Convert the body to JSON.
Methods inherited from Readable
#call, #each, #finish, #join, #stream?
Constructor Details
#initialize(body) ⇒ Wrapper
Initialize the wrapper with the given body.
26 27 28 |
# File 'lib/protocol/http/body/wrapper.rb', line 26 def initialize(body) @body = body end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
31 32 33 |
# File 'lib/protocol/http/body/wrapper.rb', line 31 def body @body end |
Class Method Details
.wrap(message) ⇒ Object
Wrap the body of the given message in a new instance of this class.
17 18 19 20 21 |
# File 'lib/protocol/http/body/wrapper.rb', line 17 def self.wrap() if body = .body .body = self.new(body) end end |
Instance Method Details
#as_json ⇒ Object
Convert the body to a hash suitable for serialization.
86 87 88 89 90 91 |
# File 'lib/protocol/http/body/wrapper.rb', line 86 def as_json(...) { class: self.class.name, body: @body&.as_json } end |
#buffered ⇒ Object
Forwards to the wrapped body.
54 55 56 |
# File 'lib/protocol/http/body/wrapper.rb', line 54 def buffered @body.buffered end |
#close(error = nil) ⇒ Object
Close the body.
36 37 38 39 40 41 |
# File 'lib/protocol/http/body/wrapper.rb', line 36 def close(error = nil) @body.close(error) # It's a no-op: # super end |
#discard ⇒ Object
Forwards to the wrapped body.
79 80 81 |
# File 'lib/protocol/http/body/wrapper.rb', line 79 def discard @body.discard end |
#empty? ⇒ Boolean
Forwards to the wrapped body.
44 45 46 |
# File 'lib/protocol/http/body/wrapper.rb', line 44 def empty? @body.empty? end |
#inspect ⇒ Object
Inspect the wrapped body. The wrapper, by default, is transparent.
103 104 105 |
# File 'lib/protocol/http/body/wrapper.rb', line 103 def inspect @body.inspect end |
#length ⇒ Object
Forwards to the wrapped body.
69 70 71 |
# File 'lib/protocol/http/body/wrapper.rb', line 69 def length @body.length end |
#read ⇒ Object
Forwards to the wrapped body.
74 75 76 |
# File 'lib/protocol/http/body/wrapper.rb', line 74 def read @body.read end |
#ready? ⇒ Boolean
Forwards to the wrapped body.
49 50 51 |
# File 'lib/protocol/http/body/wrapper.rb', line 49 def ready? @body.ready? end |
#rewind ⇒ Object
Forwards to the wrapped body.
59 60 61 |
# File 'lib/protocol/http/body/wrapper.rb', line 59 def rewind @body.rewind end |
#rewindable? ⇒ Boolean
Forwards to the wrapped body.
64 65 66 |
# File 'lib/protocol/http/body/wrapper.rb', line 64 def rewindable? @body.rewindable? end |
#The wrapped body.=(wrappedbody. = (value)) ⇒ Object
31 |
# File 'lib/protocol/http/body/wrapper.rb', line 31 attr :body |
#to_json ⇒ Object
Convert the body to JSON.
96 97 98 |
# File 'lib/protocol/http/body/wrapper.rb', line 96 def to_json(...) as_json.to_json(...) end |