lib/io_streams/row/writer.rb in iostreams-1.2.0 vs lib/io_streams/row/writer.rb in iostreams-1.2.1
- old
+ new
@@ -10,21 +10,21 @@
class Writer < IOStreams::Writer
# Write a record from an Array at a time to a stream.
#
# Note:
# - The supplied stream _must_ already be a line stream, or a stream that responds to :<<
- def self.stream(line_writer, original_file_name: nil, **args)
+ def self.stream(line_writer, **args)
# Pass-through if already a row writer
return yield(line_writer) if line_writer.is_a?(self.class)
yield new(line_writer, **args)
end
# When writing to a file also add the line writer stream
def self.file(file_name, original_file_name: file_name, delimiter: $/, **args, &block)
IOStreams::Line::Writer.file(file_name, original_file_name: original_file_name, delimiter: delimiter) do |io|
- yield new(io, **args, &block)
+ yield new(io, original_file_name: original_file_name, **args, &block)
end
end
# Create a Tabular writer that takes individual rows as arrays.
#
@@ -34,13 +34,13 @@
#
# format: [Symbol]
# :csv, :hash, :array, :json, :psv, :fixed
#
# For all other parameters, see Tabular::Header.new
- def initialize(line_writer, columns: nil, **args)
+ def initialize(line_writer, columns: nil, original_file_name: nil, **args)
raise(ArgumentError, "Stream must be a IOStreams::Line::Writer or implement #<<") unless line_writer.respond_to?(:<<)
- @tabular = IOStreams::Tabular.new(columns: columns, **args)
+ @tabular = IOStreams::Tabular.new(columns: columns, file_name: original_file_name, **args)
@line_writer = line_writer
# Render header line when `columns` is supplied.
line_writer << @tabular.render_header if columns && @tabular.requires_header?
end