Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/remote_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ def gets(...)
local_file.gets(...)
end

def each_line(...)
return to_enum(__method__, ...) unless block_given?
local_file.each_line(...)
self
end

def each_chunk(&block)
return to_enum(__method__) unless block_given?
download(&block)
Expand Down
36 changes: 36 additions & 0 deletions test/test-remote-input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,42 @@ def test_gets_after_close
end
end

def test_each_line
open_input do |input|
input.send(:cache_path).parent.mkpath
input.send(:cache_path).write("1\n2\n")
assert_equal(["1\n", "2\n"],
input.each_line.to_a)
end
end

def test_each_line_with_nil_separator
open_input do |input|
input.send(:cache_path).parent.mkpath
input.send(:cache_path).write("1\n2\n")
assert_equal(["1\n2\n"],
input.each_line(nil).to_a)
end
end

def test_each_line_with_chomp
open_input do |input|
input.send(:cache_path).parent.mkpath
input.send(:cache_path).write("1\n2\n")
assert_equal(["1", "2"],
input.each_line(chomp: true).to_a)
end
end

def test_each_line_return_self
open_input do |input|
input.send(:cache_path).parent.mkpath
input.send(:cache_path).write("1\n2\n")
assert_same(input,
input.each_line {})
end
end

def test_each_chunk
open_input do |input|
expected_chunks = ["1" * (1024 * 1024), "2"]
Expand Down
Loading