Skip to content

Commit 7ace618

Browse files
committed
Improve consistency of method names/usage.
1 parent ea2ea41 commit 7ace618

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

lib/protocol/http/body/buffered.rb

+12-3
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,28 @@ class Buffered < Readable
1717
#
1818
# @parameter body [String | Array(String) | Readable | nil] the body to wrap.
1919
# @returns [Readable | nil] the wrapped body or nil if nil was given.
20-
def self.wrap(body)
20+
def self.for(body)
2121
if body.is_a?(Readable)
2222
return body
2323
elsif body.is_a?(Array)
2424
return self.new(body)
2525
elsif body.is_a?(String)
2626
return self.new([body])
2727
elsif body
28-
return self.for(body)
28+
return self.read(body)
2929
end
3030
end
3131

32-
def self.for(body)
32+
# @deprecated Use {#for} instead.
33+
def self.wrap(body)
34+
self.for(body)
35+
end
36+
37+
# Read the entire body into a buffered representation.
38+
#
39+
# @parameter body [Readable] the body to read.
40+
# @returns [Buffered] the buffered body.
41+
def self.read(body)
3342
chunks = []
3443

3544
body.each do |chunk|

lib/protocol/http/body/readable.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def call(stream)
6666
# @returns [Buffered] The buffered body.
6767
def finish
6868
# Internally, this invokes `self.each` which then invokes `self.close`.
69-
Buffered.for(self)
69+
Buffered.read(self)
7070
end
7171

7272
# Enumerate all chunks until finished, then invoke `#close`.

lib/protocol/http/body/rewindable.rb

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ module HTTP
1111
module Body
1212
# A body which buffers all it's contents as it is `#read`.
1313
class Rewindable < Wrapper
14+
def self.for(body)
15+
if body.rewindable?
16+
body
17+
else
18+
self.new(body)
19+
end
20+
end
21+
1422
def initialize(body)
1523
super(body)
1624

test/protocol/http/body/inflate.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
let(:sample) {"The quick brown fox jumps over the lazy dog."}
1515
let(:chunks) {[sample] * 1024}
1616

17-
let(:body) {Protocol::HTTP::Body::Buffered.for(chunks)}
17+
let(:body) {Protocol::HTTP::Body::Buffered.new(chunks)}
1818
let(:deflate_body) {Protocol::HTTP::Body::Deflate.for(body)}
1919
let(:compressed_chunks) {deflate_body.join.each_char.to_a}
2020
let(:compressed_body_chunks) {compressed_chunks}

0 commit comments

Comments
 (0)