progressive_io 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea6428465be21d680077d7ed5077c9e8e8f0f72622249e3ccb2f585f38e7d969
4
- data.tar.gz: f71c4577f2642efb23c3df42697cc52ce08a7cca603af89825efaf5c760c32b0
3
+ metadata.gz: e46f28055cb41f75b5a00b863d1771580ec7e610dd09d5360574e123c3b99867
4
+ data.tar.gz: b9ff8b9bf2724da050eb49933eac10c9d35953c30abd823fcc0482823a27a3a8
5
5
  SHA512:
6
- metadata.gz: ad62723654f1655d14b3a6b391581b1adcef7dbe27bf9a05901f405703118cb251b1bd4b4639ad3ce81d6099ba031596402ce16b96a54476ecdb2ddfa90cdba0
7
- data.tar.gz: c1b87a837cb5f2a10defbf2dd1ec493b90b42db58f717b1aca2dfc6827af134fd223d4ca91e307ece53f0560e843fefc02b077f3cd72db47eed6e286f9a927e9
6
+ metadata.gz: e9c3bdfaf294545502b5dcde2381f67c4d343df02c64d9b56d290877f13619d283288a64517af7e5c5aa7f7359db6a0606684f693c0b8cdec9c32abfd2d27a43
7
+ data.tar.gz: 14fbce5195814ef1c583c664f8550b664e60d2d46a1465ef7ced873bd980247897fea75652f36444c4ff5511c67ba8be64dcd25644a310f907cd80d9f68ba236
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 2.0.2
2
+
3
+ * Fix `each_line` to return an Enumerator that properly references `:each_line` method
4
+ when called without a block. Previously, `each_line` was an alias of `each`, causing
5
+ the returned Enumerator to reference `:each` instead of `:each_line`.
6
+ * Change `each` and `each_line` to accept variadic arguments (`*args`) for proper
7
+ forwarding of separator and limit parameters.
8
+
1
9
  ## 2.0.1
2
10
 
3
11
  * Revert back to using SimpleDelegator - it's just easier.
@@ -28,7 +28,7 @@ require 'delegate'
28
28
  # @since 2.0.0
29
29
  class ProgressiveIO < SimpleDelegator
30
30
  # The version of the ProgressiveIO library
31
- VERSION = '2.0.1'
31
+ VERSION = '2.0.2'
32
32
 
33
33
  # @return [Proc, nil] The progress callback block that will be called when data is read
34
34
  # The block receives one parameter: current position
@@ -54,22 +54,51 @@ class ProgressiveIO < SimpleDelegator
54
54
 
55
55
  # Iterates over the IO stream line by line, calling the progress block for each line.
56
56
  #
57
- # @param sep_string [String] The line separator (defaults to $/)
57
+ # @param args [Array] Arguments to pass to the underlying IO#each method (separator and/or limit)
58
58
  # @yield [line] Each line from the IO stream
59
59
  # @yieldparam line [String] A line from the IO stream
60
60
  # @return [Enumerator] An enumerator if no block is given
61
61
  #
62
62
  # @example
63
- # progress_io.each_line do |line|
63
+ # progress_io.each do |line|
64
64
  # puts "Processing: #{line.chomp}"
65
65
  # end
66
- def each(sep_string = $/, &blk)
66
+ #
67
+ # @example Using as an Enumerator
68
+ # progress_io.each.with_index do |line, idx|
69
+ # puts "Line #{idx}: #{line.chomp}"
70
+ # end
71
+ def each(*args, &blk)
72
+ return enum_for(__method__, *args) unless block_given?
73
+
67
74
  # Report offset at each call of the iterator
68
- super(sep_string) do |line|
75
+ super(*args) do |line|
69
76
  yield(line).tap { notify_read }
70
77
  end
71
78
  end
72
- alias_method :each_line, :each
79
+
80
+ # Iterates over the IO stream line by line, calling the progress block for each line.
81
+ # This is an alias-like method for {#each} that ensures proper Enumerator behavior.
82
+ #
83
+ # @param args [Array] Arguments to pass to the underlying IO#each_line method (separator and/or limit)
84
+ # @yield [line] Each line from the IO stream
85
+ # @yieldparam line [String] A line from the IO stream
86
+ # @return [Enumerator] An enumerator if no block is given
87
+ #
88
+ # @example
89
+ # progress_io.each_line do |line|
90
+ # puts "Processing: #{line.chomp}"
91
+ # end
92
+ #
93
+ # @example Using as an Enumerator
94
+ # progress_io.each_line.with_index do |line, idx|
95
+ # puts "Line #{idx}: #{line.chomp}"
96
+ # end
97
+ def each_line(*args, &blk)
98
+ return enum_for(__method__, *args) unless block_given?
99
+
100
+ each(*args, &blk)
101
+ end
73
102
 
74
103
  # Iterates over the IO stream byte by byte, calling the progress block for each byte.
75
104
  #
@@ -81,7 +110,14 @@ class ProgressiveIO < SimpleDelegator
81
110
  # progress_io.each_byte do |byte|
82
111
  # puts "Byte: #{byte}"
83
112
  # end
113
+ #
114
+ # @example Using as an Enumerator
115
+ # progress_io.each_byte.with_index do |byte, idx|
116
+ # puts "Byte #{idx}: #{byte}"
117
+ # end
84
118
  def each_byte(&blk)
119
+ return enum_for(__method__) unless block_given?
120
+
85
121
  # Report offset at each call of the iterator
86
122
  super { |b| yield(b).tap { notify_read } }
87
123
  end
@@ -29,6 +29,73 @@ class TestProgressiveIO < Minitest::Test
29
29
  assert_equal [[5], [9], [18], [22]], messages
30
30
  end
31
31
 
32
+ def test_each_returns_enumerator_without_block
33
+ io, messages = e("Mary\nHad\nA little\nLamb"), []
34
+
35
+ io.progress_block = lambda do | offset |
36
+ messages.push([offset])
37
+ end
38
+
39
+ enum = io.each
40
+ assert_kind_of Enumerator, enum
41
+
42
+ # Enumerator should yield lines and still trigger progress callbacks
43
+ lines = enum.to_a
44
+ assert_equal ["Mary\n", "Had\n", "A little\n", "Lamb"], lines
45
+ assert_equal [[5], [9], [18], [22]], messages
46
+ end
47
+
48
+ def test_each_line_returns_enumerator_without_block
49
+ io, messages = e("Mary\nHad\nA little\nLamb"), []
50
+
51
+ io.progress_block = lambda do | offset |
52
+ messages.push([offset])
53
+ end
54
+
55
+ enum = io.each_line
56
+ assert_kind_of Enumerator, enum
57
+
58
+ # Enumerator should yield lines and still trigger progress callbacks
59
+ lines = enum.to_a
60
+ assert_equal ["Mary\n", "Had\n", "A little\n", "Lamb"], lines
61
+ assert_equal [[5], [9], [18], [22]], messages
62
+ end
63
+
64
+ def test_each_enumerator_with_custom_separator
65
+ io, messages = e("Mary|Had|A little|Lamb"), []
66
+
67
+ io.progress_block = lambda do | offset |
68
+ messages.push([offset])
69
+ end
70
+
71
+ enum = io.each("|")
72
+ assert_kind_of Enumerator, enum
73
+
74
+ lines = enum.to_a
75
+ assert_equal ["Mary|", "Had|", "A little|", "Lamb"], lines
76
+ assert_equal [[5], [9], [18], [22]], messages
77
+ end
78
+
79
+ def test_each_enumerator_chainable
80
+ io = e("Mary\nHad\nA little\nLamb")
81
+
82
+ # Should be chainable with Enumerator methods like with_index
83
+ result = io.each.with_index.map { |line, idx| [idx, line.chomp] }
84
+ assert_equal [[0, "Mary"], [1, "Had"], [2, "A little"], [3, "Lamb"]], result
85
+ end
86
+
87
+ def test_each_line_enumerator_references_each_line_method
88
+ io = e("Mary\nHad\nLamb")
89
+
90
+ # The enumerator returned by each_line should reference :each_line, not :each
91
+ # This is important for proper Enumerator behavior and introspection
92
+ each_enum = io.each
93
+ each_line_enum = io.each_line
94
+
95
+ assert_match(/:each\b/, each_enum.inspect, "each enumerator should reference :each method")
96
+ assert_match(/:each_line\b/, each_line_enum.inspect, "each_line enumerator should reference :each_line method")
97
+ end
98
+
32
99
  def test_each_byte
33
100
  io, messages = e("123"), []
34
101
 
@@ -42,6 +109,30 @@ class TestProgressiveIO < Minitest::Test
42
109
  assert_equal [[1], [2], [3]], messages
43
110
  end
44
111
 
112
+ def test_each_byte_returns_enumerator_without_block
113
+ io, messages = e("123"), []
114
+
115
+ io.progress_block = lambda do | offset |
116
+ messages.push([offset])
117
+ end
118
+
119
+ enum = io.each_byte
120
+ assert_kind_of Enumerator, enum
121
+
122
+ # Enumerator should yield bytes and still trigger progress callbacks
123
+ bytes = enum.to_a
124
+ assert_equal [49, 50, 51], bytes
125
+ assert_equal [[1], [2], [3]], messages
126
+ end
127
+
128
+ def test_each_byte_enumerator_chainable
129
+ io = e("123")
130
+
131
+ # Should be chainable with Enumerator methods like with_index
132
+ result = io.each_byte.with_index.map { |byte, idx| [idx, byte] }
133
+ assert_equal [[0, 49], [1, 50], [2, 51]], result
134
+ end
135
+
45
136
  def test_getc
46
137
  io = e("123")
47
138
  io.progress_block = lambda do | offset |
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: progressive_io
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julik Tarkhanov
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-08-01 00:00:00.000000000 Z
10
+ date: 2026-01-13 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rake