Class: Omnizip::IO::Sink
- Inherits:
-
Object
- Object
- Omnizip::IO::Sink
- Defined in:
- lib/omnizip/io/source.rb
Overview
Polymorphic adapter for "things we can write bytes to".
Adapters:
- +IO+/+StringIO+/+Tempfile+ → wrapped as-is
String→ treated as a file path; writes viaFile.binwriteObjectresponding to:write→ delegated to
Defined Under Namespace
Classes: PathSink
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(io) ⇒ Sink
constructor
A new instance of Sink.
- #write(data) ⇒ Object
Constructor Details
#initialize(io) ⇒ Sink
Returns a new instance of Sink.
107 108 109 |
# File 'lib/omnizip/io/source.rb', line 107 def initialize(io) @io = io end |
Class Method Details
.for(output) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/omnizip/io/source.rb', line 93 def self.for(output) case output when ::IO, ::StringIO, ::Tempfile then new(output) when String then PathSink.new(output) else unless output.respond_to?(:write) raise ArgumentError, "Cannot adapt #{output.inspect} to Omnizip::IO::Sink" end new(output) end end |
Instance Method Details
#close ⇒ Object
115 116 117 |
# File 'lib/omnizip/io/source.rb', line 115 def close @io.close if @io.respond_to?(:close) end |
#write(data) ⇒ Object
111 112 113 |
# File 'lib/omnizip/io/source.rb', line 111 def write(data) @io.write(data) end |