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))
end

Instance Method Details

#closeObject



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

def close
  path = @tempfile.path
  @tempfile.close
  @closer.call(path) if @closer
  @tempfile.unlink
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