Class: BFS::TempWriter

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

Instance Method Summary collapse

Constructor Details

#initialize(name, opts = {}, &closer) ⇒ TempWriter

Returns a new instance of TempWriter.



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

def initialize(name, opts={}, &closer)
  opts = opts.merge(binmode: true) unless opts[:encoding]

  @closer = closer
  @tempfile = ::Tempfile.new(File.basename(name.to_s), opts)
end

Instance Method Details

#closeObject



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

def close
  return if closed?

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

#closed?Boolean

Returns:

  • (Boolean)


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

def closed?
  @tempfile.closed?
end

#pathObject



12
13
14
# File 'lib/bfs/helpers.rb', line 12

def path
  @tempfile.path
end

#write(data) ⇒ Object



16
17
18
# File 'lib/bfs/helpers.rb', line 16

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