Class: BFS::TempWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/bfs/helpers.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, &closer) ⇒ TempWriter

Returns a new instance of TempWriter.



5
6
7
8
# File 'lib/bfs/helpers.rb', line 5

def initialize(name, &closer)
  @closer = closer
  @tempfile = ::Tempfile.new(File.basename(name.to_s), binmode: true)
end

Instance Method Details

#closeObject



22
23
24
25
26
27
28
29
# File 'lib/bfs/helpers.rb', line 22

def close
  return if closed?

  path = @tempfile.path
  @tempfile.close
  @closer.call(path) if @closer
  @tempfile.unlink
end

#closed?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/bfs/helpers.rb', line 18

def closed?
  @tempfile.closed?
end

#pathObject



10
11
12
# File 'lib/bfs/helpers.rb', line 10

def path
  @tempfile.path
end

#write(data) ⇒ Object



14
15
16
# File 'lib/bfs/helpers.rb', line 14

def write(data)
  @tempfile.write(data)
end