Sha256: 6a652975e77b848a51c4fb001c7d76349f923ad18d07504ac77ec4c137e362d3

Contents?: true

Size: 623 Bytes

Versions: 8

Compression:

Stored size: 623 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

8 entries across 8 versions & 1 rubygems

Version Path
dino_utils-0.1.21 lib/tn/temp_file.rb
dino_utils-0.1.20 lib/tn/temp_file.rb
dino_utils-0.1.19 lib/tn/temp_file.rb
dino_utils-0.1.18 lib/tn/temp_file.rb
dino_utils-0.1.16 lib/tn/temp_file.rb
dino_utils-0.1.15 lib/tn/temp_file.rb
dino_utils-0.1.14 lib/tn/temp_file.rb
dino_utils-0.1.13 lib/tn/temp_file.rb