lib/io_streams/stream.rb in iostreams-1.2.1 vs lib/io_streams/stream.rb in iostreams-1.3.0

- old
+ new

@@ -15,26 +15,26 @@ # # See #option to set an option for one of the streams included based on the file name extensions. # # Example: # - # IOStreams.path('tempfile2527').stream(:zip).stream(:pgp, passphrase: 'receiver_passphrase').reader(&:read) + # IOStreams.path("tempfile2527").stream(:zip).stream(:pgp, passphrase: "receiver_passphrase").read def stream(stream, **options) builder.stream(stream, **options) self end # Set the options for an element within the stream for this file. # If the relevant stream is not found for this file it is ignored. # For example, if the file does not have a pgp extension then the pgp option is not relevant. # - # IOStreams.path('keep_safe.pgp').option(:pgp, passphrase: 'receiver_passphrase').reader(&:read) + # IOStreams.path("keep_safe.pgp").option(:pgp, passphrase: "receiver_passphrase").read # # # In this case the file is not pgp so the `passphrase` option is ignored. - # IOStreams.path('keep_safe.enc').option(:pgp, passphrase: 'receiver_passphrase').reader(&:read) + # IOStreams.path("keep_safe.enc").option(:pgp, passphrase: "receiver_passphrase").read # - # IOStreams.path(output_file_name).option(:pgp, passphrase: 'receiver_passphrase').reader(&:read) + # IOStreams.path(output_file_name).option(:pgp, passphrase: "receiver_passphrase").read def option(stream, **options) builder.option(stream, **options) self end @@ -280,11 +280,16 @@ end def line_reader(embedded_within: nil, **args) embedded_within = '"' if embedded_within.nil? && builder.file_name&.include?(".csv") - stream_reader { |io| yield IOStreams::Line::Reader.new(io, original_file_name: builder.file_name, embedded_within: embedded_within, **args) } + stream_reader do |io| + yield IOStreams::Line::Reader.new(io, + original_file_name: builder.file_name, + embedded_within: embedded_within, + **args) + end end # Iterate over a file / stream returning each line as an array, one at a time. def row_reader(delimiter: nil, embedded_within: nil, **args) line_reader(delimiter: delimiter, embedded_within: embedded_within) do |io| @@ -304,21 +309,27 @@ end def line_writer(**args, &block) return block.call(io_stream) if io_stream&.is_a?(IOStreams::Line::Writer) - writer { |io| IOStreams::Line::Writer.stream(io, original_file_name: builder.file_name, **args, &block) } + writer do |io| + IOStreams::Line::Writer.stream(io, original_file_name: builder.file_name, **args, &block) + end end def row_writer(delimiter: $/, **args, &block) return block.call(io_stream) if io_stream&.is_a?(IOStreams::Row::Writer) - line_writer(delimiter: delimiter) { |io| IOStreams::Row::Writer.stream(io, original_file_name: builder.file_name, **args, &block) } + line_writer(delimiter: delimiter) do |io| + IOStreams::Row::Writer.stream(io, original_file_name: builder.file_name, **args, &block) + end end def record_writer(delimiter: $/, **args, &block) return block.call(io_stream) if io_stream&.is_a?(IOStreams::Record::Writer) - line_writer(delimiter: delimiter) { |io| IOStreams::Record::Writer.stream(io, original_file_name: builder.file_name, **args, &block) } + line_writer(delimiter: delimiter) do |io| + IOStreams::Record::Writer.stream(io, original_file_name: builder.file_name, **args, &block) + end end end end