Sha256: 923893d02db295a4a94e0e0dcf15cae93b13fef740e8d3826d9b1621f592cf7a

Contents?: true

Size: 648 Bytes

Versions: 66

Compression:

Stored size: 648 Bytes

Contents

require 'tmpdir'

module Tins
  module TempIO
    def temp_io(content: nil, name: __method__)
      content.nil? and raise ArgumentError, "missing keyword: content"
      name = File.basename(name.to_s)
      Dir.mktmpdir do |dir|
        name = File.join(dir, name)
        File.open(name, 'w+b') do |io|
          if content.respond_to?(:call)
            if content.respond_to?(:arity) && content.arity == 1
              content.call(io)
            else
              io.write content.call
            end
          else
            io.write content
          end
          io.rewind
          yield io
        end
      end
    end
  end
end

Version data entries

66 entries across 55 versions & 2 rubygems

Version Path
tins-1.38.0 lib/tins/temp_io.rb
tins-1.37.1 lib/tins/temp_io.rb
tins-1.37.0 lib/tins/temp_io.rb
tins-1.36.1 lib/tins/temp_io.rb
tins-1.36.0 lib/tins/temp_io.rb
tins-1.35.0 lib/tins/temp_io.rb
tins-1.34.0 lib/tins/temp_io.rb
tins-1.33.0 lib/tins/temp_io.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/lib/tins/temp_io.rb
tins-1.32.1 lib/tins/temp_io.rb
tins-1.32.0 lib/tins/temp_io.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/lib/tins/temp_io.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/lib/tins/temp_io.rb
tins-1.31.1 lib/tins/temp_io.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/tins-1.31.0/lib/tins/temp_io.rb
tins-1.31.0 lib/tins/temp_io.rb
tins-1.30.0 lib/tins/temp_io.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/tins-1.29.1/lib/tins/temp_io.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/tins-1.29.1/lib/tins/temp_io.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/tins-1.29.1/lib/tins/temp_io.rb