Class: Tins::TempIO::Enum
- Includes:
- Tins::TempIO
- Defined in:
- lib/tins/temp_io_enum.rb
Instance Method Summary collapse
-
#initialize(chunk_size: 2 ** 16, filename: nil, &content_proc) ⇒ Enum
constructor
A new instance of Enum.
Methods included from Tins::TempIO
Constructor Details
#initialize(chunk_size: 2 ** 16, filename: nil, &content_proc) ⇒ Enum
Returns a new instance of Enum.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/tins/temp_io_enum.rb', line 8 def initialize(chunk_size: 2 ** 16, filename: nil, &content_proc) content_proc or raise ArgumentError, 'need a content proc as block argument' super() do |y| temp_io(name: 'some-stream', content: content_proc) do |file| until file.eof? y.yield file.read(chunk_size) end end end.tap do |enum| if filename enum.define_singleton_method(:filename) do filename end end end end |