Class: IOStreams::Writer
- Inherits:
-
Object
- Object
- IOStreams::Writer
- Defined in:
- lib/io_streams/writer.rb
Direct Known Subclasses
Bzip2::Writer, Encode::Writer, Gzip::Writer, Line::Writer, Pgp::Writer, Record::Writer, Row::Writer, SymmetricEncryption::Writer, Zip::Writer
Instance Attribute Summary collapse
-
#output_stream ⇒ Object
readonly
Returns the value of attribute output_stream.
Class Method Summary collapse
-
.file(file_name, original_file_name: file_name, **args, &block) ⇒ Object
When a Writer supports streams, also allow it to simply support a file.
-
.open(file_name_or_io, **args, &block) ⇒ Object
For processing by either a file name or an open IO stream.
-
.stream(output_stream, original_file_name: nil, **args, &block) ⇒ Object
When a Writer does not support streams, we copy the stream to a local temp file and then pass that filename in for this reader.
Instance Method Summary collapse
-
#initialize(output_stream) ⇒ Writer
constructor
A new instance of Writer.
Constructor Details
#initialize(output_stream) ⇒ Writer
Returns a new instance of Writer.
24 25 26 |
# File 'lib/io_streams/writer.rb', line 24 def initialize(output_stream) @output_stream = output_stream end |
Instance Attribute Details
#output_stream ⇒ Object (readonly)
Returns the value of attribute output_stream.
22 23 24 |
# File 'lib/io_streams/writer.rb', line 22 def output_stream @output_stream end |
Class Method Details
.file(file_name, original_file_name: file_name, **args, &block) ⇒ Object
When a Writer supports streams, also allow it to simply support a file
13 14 15 |
# File 'lib/io_streams/writer.rb', line 13 def self.file(file_name, original_file_name: file_name, **args, &block) ::File.open(file_name, "wb") { |file| stream(file, original_file_name: original_file_name, **args, &block) } end |
.open(file_name_or_io, **args, &block) ⇒ Object
For processing by either a file name or an open IO stream.
18 19 20 |
# File 'lib/io_streams/writer.rb', line 18 def self.open(file_name_or_io, **args, &block) file_name_or_io.is_a?(String) ? file(file_name_or_io, **args, &block) : stream(file_name_or_io, **args, &block) end |
.stream(output_stream, original_file_name: nil, **args, &block) ⇒ Object
When a Writer does not support streams, we copy the stream to a local temp file and then pass that filename in for this reader.
5 6 7 8 9 10 |
# File 'lib/io_streams/writer.rb', line 5 def self.stream(output_stream, original_file_name: nil, **args, &block) Utils.temp_file_name("iostreams_writer") do |file_name| file(file_name, original_file_name: original_file_name, **args, &block) ::File.open(file_name, "rb") { |source| ::IO.copy_stream(source, output_stream) } end end |