Class: Purplelight::WriterCSV::CountingIO
- Inherits:
-
Object
- Object
- Purplelight::WriterCSV::CountingIO
- Defined in:
- lib/purplelight/writer_csv.rb
Overview
Minimal wrapper to count bytes written for rotate logic when underlying compressed writer doesn’t expose position (e.g., zstd-ruby).
Instance Method Summary collapse
-
#<<(data) ⇒ Object
CSV calls ‘<<’ on the underlying IO in some code paths.
-
#flush ⇒ Object
CSV#flush may forward flush to underlying IO; make it a no-op if unavailable.
-
#initialize(io, on_write:) ⇒ CountingIO
constructor
A new instance of CountingIO.
- #method_missing(method_name) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
- #write(data) ⇒ Object
Constructor Details
#initialize(io, on_write:) ⇒ CountingIO
Returns a new instance of CountingIO.
103 104 105 106 |
# File 'lib/purplelight/writer_csv.rb', line 103 def initialize(io, on_write:) @io = io @on_write = on_write end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
124 125 126 |
# File 'lib/purplelight/writer_csv.rb', line 124 def method_missing(method_name, *, &) @io.send(method_name, *, &) end |
Instance Method Details
#<<(data) ⇒ Object
CSV calls ‘<<’ on the underlying IO in some code paths
115 116 117 |
# File 'lib/purplelight/writer_csv.rb', line 115 def <<(data) write(data) end |
#flush ⇒ Object
CSV#flush may forward flush to underlying IO; make it a no-op if unavailable
120 121 122 |
# File 'lib/purplelight/writer_csv.rb', line 120 def flush @io.flush if @io.respond_to?(:flush) end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
128 129 130 |
# File 'lib/purplelight/writer_csv.rb', line 128 def respond_to_missing?(method_name, include_private = false) @io.respond_to?(method_name, include_private) end |
#write(data) ⇒ Object
108 109 110 111 112 |
# File 'lib/purplelight/writer_csv.rb', line 108 def write(data) bytes_written = @io.write(data) @on_write.call(bytes_written) if bytes_written && @on_write bytes_written end |