progressive_io 2.0.0 → 2.0.1

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/lib/progressive_io.rb +18 -31
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b644b242893003aa43e9f2c9ec382abc77ed6f08aef0acf13612fd8c01af6109
4
- data.tar.gz: 9ceb2436e366cb6cc823fd1e1600a07d99f7ea3aa07ca299647050b410eab9e7
3
+ metadata.gz: ea6428465be21d680077d7ed5077c9e8e8f0f72622249e3ccb2f585f38e7d969
4
+ data.tar.gz: f71c4577f2642efb23c3df42697cc52ce08a7cca603af89825efaf5c760c32b0
5
5
  SHA512:
6
- metadata.gz: 800ce4c7128151cdf980f61fb50e2aa7c4811f0bad753535ee438fc2925b3d84018a176f633a18d27783af158dc8667b18623261ab8cccc460364b50f5958cae
7
- data.tar.gz: 7cf60a1881e77bd39f2bf0dcff6cb9252c72130a24f1daaf2ede3fa62b9c90239a5d2d6a01f9d838b8f4ed79114e8811619c4f8955969a200b1e0e52152e4013
6
+ metadata.gz: ad62723654f1655d14b3a6b391581b1adcef7dbe27bf9a05901f405703118cb251b1bd4b4639ad3ce81d6099ba031596402ce16b96a54476ecdb2ddfa90cdba0
7
+ data.tar.gz: c1b87a837cb5f2a10defbf2dd1ec493b90b42db58f717b1aca2dfc6827af134fd223d4ca91e307ece53f0560e843fefc02b077f3cd72db47eed6e286f9a927e9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 2.0.1
2
+
3
+ * Revert back to using SimpleDelegator - it's just easier.
4
+
1
5
  ## 2.0.0
2
6
 
3
7
  * Added comprehensive documentation with examples
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'delegate'
4
+
3
5
  # A wrapper class that provides progress tracking for IO operations.
4
6
  #
5
7
  # This class wraps an IO object and calls a progress block whenever data is read,
@@ -24,9 +26,9 @@
24
26
  # content = progress_io.read
25
27
  #
26
28
  # @since 2.0.0
27
- class ProgressiveIO
29
+ class ProgressiveIO < SimpleDelegator
28
30
  # The version of the ProgressiveIO library
29
- VERSION = '2.0.0'
31
+ VERSION = '2.0.1'
30
32
 
31
33
  # @return [Proc, nil] The progress callback block that will be called when data is read
32
34
  # The block receives one parameter: current position
@@ -46,7 +48,7 @@ class ProgressiveIO
46
48
  # puts "Read #{pos} bytes"
47
49
  # end
48
50
  def initialize(with_io, &blk)
49
- @io = with_io
51
+ super(with_io)
50
52
  @progress_block = blk.to_proc if blk
51
53
  end
52
54
 
@@ -63,7 +65,7 @@ class ProgressiveIO
63
65
  # end
64
66
  def each(sep_string = $/, &blk)
65
67
  # Report offset at each call of the iterator
66
- @io.each(sep_string) do | line |
68
+ super(sep_string) do |line|
67
69
  yield(line).tap { notify_read }
68
70
  end
69
71
  end
@@ -81,7 +83,7 @@ class ProgressiveIO
81
83
  # end
82
84
  def each_byte(&blk)
83
85
  # Report offset at each call of the iterator
84
- @io.each_byte { |b| yield(b).tap { notify_read } }
86
+ super { |b| yield(b).tap { notify_read } }
85
87
  end
86
88
 
87
89
  # Reads a single character from the IO stream.
@@ -89,7 +91,7 @@ class ProgressiveIO
89
91
  # @return [String, nil] The next character or nil if at end of stream
90
92
  # @see IO#getc
91
93
  def getc
92
- inner(:getc)
94
+ super.tap { notify_read }
93
95
  end
94
96
 
95
97
  # Reads a line from the IO stream.
@@ -98,7 +100,7 @@ class ProgressiveIO
98
100
  # @return [String, nil] The next line or nil if at end of stream
99
101
  # @see IO#gets
100
102
  def gets(*args)
101
- inner(:gets, *args)
103
+ super(*args).tap { notify_read }
102
104
  end
103
105
 
104
106
  # Reads data from the IO stream.
@@ -107,7 +109,7 @@ class ProgressiveIO
107
109
  # @return [String, nil] The read data or nil if at end of stream
108
110
  # @see IO#read
109
111
  def read(*a)
110
- inner(:read, *a)
112
+ super(*a).tap { notify_read }
111
113
  end
112
114
 
113
115
  # Reads a specific number of bytes from the IO stream.
@@ -116,7 +118,7 @@ class ProgressiveIO
116
118
  # @return [String] The read bytes
117
119
  # @see IO#readbytes
118
120
  def readbytes(*a)
119
- inner(:readbytes, *a)
121
+ super(*a).tap { notify_read }
120
122
  end
121
123
 
122
124
  # Reads a single character from the IO stream.
@@ -125,7 +127,7 @@ class ProgressiveIO
125
127
  # @raise [EOFError] If at end of stream
126
128
  # @see IO#readchar
127
129
  def readchar
128
- inner(:readchar)
130
+ super.tap { notify_read }
129
131
  end
130
132
 
131
133
  # Reads a line from the IO stream.
@@ -135,7 +137,7 @@ class ProgressiveIO
135
137
  # @raise [EOFError] If at end of stream
136
138
  # @see IO#readline
137
139
  def readline(*a)
138
- inner(:readline, *a)
140
+ super(*a).tap { notify_read }
139
141
  end
140
142
 
141
143
  # Reads all lines from the IO stream.
@@ -144,7 +146,7 @@ class ProgressiveIO
144
146
  # @return [Array<String>] Array of lines
145
147
  # @see IO#readlines
146
148
  def readlines(*a)
147
- inner(:readlines, *a)
149
+ super(*a).tap { notify_read }
148
150
  end
149
151
 
150
152
  # Seeks to a position in the IO stream.
@@ -153,11 +155,11 @@ class ProgressiveIO
153
155
  # @return [Integer] The new position
154
156
  # @see IO#seek
155
157
  def seek(*a)
156
- inner(:seek, *a)
158
+ super(*a)
157
159
  end
158
160
 
159
161
  # def ungetc(*a)
160
- # inner(:ungetc, a)
162
+ # super(*a).tap { notify_read }
161
163
  # end
162
164
 
163
165
  # Sets the position in the IO stream.
@@ -166,31 +168,16 @@ class ProgressiveIO
166
168
  # @return [Integer] The new position
167
169
  # @see IO#pos=
168
170
  def pos=(p)
169
- inner(:pos=, p)
171
+ super(p).tap { notify_read }
170
172
  end
171
173
 
172
174
  private
173
175
 
174
- # @return [IO] The wrapped IO object
175
- def io
176
- @io
177
- end
178
-
179
- # Delegates method calls to the wrapped IO object and calls the progress block.
180
- #
181
- # @param m [Symbol] The method name to call
182
- # @param args [Array] Arguments to pass to the method
183
- # @return [Object] The result of the method call
184
- def inner(m, *args)
185
- r = @io.respond_to?(:public_send) ? @io.public_send(m, *args) : @io.send(m, *args)
186
- r.tap { notify_read }
187
- end
188
-
189
176
  # Calls the progress block with current position.
190
177
  # This method is called whenever data is read from the IO stream.
191
178
  #
192
179
  # @return [void]
193
180
  def notify_read
194
- @progress_block.call(@io.pos) if @progress_block
181
+ @progress_block.call(pos) if @progress_block
195
182
  end
196
183
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: progressive_io
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julik Tarkhanov