Sha256: fc3e6a5187cdd45c8cd38e28ef5752b387dc3f8777bac377e4b87ef19c54cf2d

Contents?: true

Size: 622 Bytes

Versions: 2

Compression:

Stored size: 622 Bytes

Contents

module TN
  class TempFile

    def initialize(content:nil, file:nil, name: 'tanga')
      extension = File.extname(name)
      file_name = SecureRandom.hex
      @file = file || ::Tempfile.new([file_name, extension])
      @file.binmode
      if content
        @file.write(content) if content
        @file.close
      end

      if block_given?
        yield(self)
        done
      end
    end

    def method_missing(method, *args, &block)
      @file.send(method, *args, &block)
    end

    def path
      File.absolute_path(@file.path)
    end

    def done
      @file.close
      @file.unlink
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dino_utils-0.1.12 lib/tn/temp_file.rb
dino_utils-0.1.11 lib/tn/temp_file.rb