File tree Expand file tree Collapse file tree 3 files changed +24
-21
lines changed Expand file tree Collapse file tree 3 files changed +24
-21
lines changed Original file line number Diff line number Diff line change @@ -11,29 +11,24 @@ module HTTP
11
11
module Body
12
12
# A body which buffers all it's contents.
13
13
class Buffered < Readable
14
- # Wraps an array into a buffered body .
14
+ # Tries to wrap an object in a {Buffered} instance .
15
15
#
16
16
# For compatibility, also accepts anything that behaves like an `Array(String)`.
17
17
#
18
18
# @parameter body [String | Array(String) | Readable | nil] the body to wrap.
19
19
# @returns [Readable | nil] the wrapped body or nil if nil was given.
20
- def self . for ( body )
21
- if body . is_a? ( Readable )
22
- return body
23
- elsif body . is_a? ( Array )
24
- return self . new ( body )
25
- elsif body . is_a? ( String )
26
- return self . new ( [ body ] )
27
- elsif body
28
- return self . read ( body )
20
+ def self . wrap ( object )
21
+ if object . is_a? ( Readable )
22
+ return object
23
+ elsif object . is_a? ( Array )
24
+ return self . new ( object )
25
+ elsif object . is_a? ( String )
26
+ return self . new ( [ object ] )
27
+ elsif object
28
+ return self . read ( object )
29
29
end
30
30
end
31
31
32
- # @deprecated Use {#for} instead.
33
- def self . wrap ( body )
34
- self . for ( body )
35
- end
36
-
37
32
# Read the entire body into a buffered representation.
38
33
#
39
34
# @parameter body [Readable] the body to read.
Original file line number Diff line number Diff line change @@ -11,11 +11,13 @@ module HTTP
11
11
module Body
12
12
# A body which buffers all it's contents as it is `#read`.
13
13
class Rewindable < Wrapper
14
- def self . for ( body )
15
- if body . rewindable?
16
- body
17
- else
18
- self . new ( body )
14
+ def self . wrap ( message )
15
+ if body = message . body
16
+ if body . rewindable?
17
+ body
18
+ else
19
+ message . body = self . new ( body )
20
+ end
19
21
end
20
22
end
21
23
@@ -34,7 +36,9 @@ def ready?
34
36
( @index < @chunks . size ) || super
35
37
end
36
38
37
- # A rewindable body wraps some other body. Convert it to a buffered body
39
+ # A rewindable body wraps some other body. Convert it to a buffered body. The buffered body will share the same chunks as the rewindable body.
40
+ #
41
+ # @returns [Buffered] the buffered body.
38
42
def buffered
39
43
Buffered . new ( @chunks )
40
44
end
Original file line number Diff line number Diff line change @@ -10,6 +10,10 @@ module HTTP
10
10
module Body
11
11
# Wrapping body instance. Typically you'd override `#read`.
12
12
class Wrapper < Readable
13
+ # Wrap the body of the given message in a new instance of this class.
14
+ #
15
+ # @parameter message [Request | Response] the message to wrap.
16
+ # @returns [Wrapper | nil] the wrapped body or nil if the body was nil.
13
17
def self . wrap ( message )
14
18
if body = message . body
15
19
message . body = self . new ( body )
You can’t perform that action at this time.
0 commit comments