Class: FluQ::Buffer::File

Inherits:
Base
  • Object
show all
Defined in:
lib/fluq/buffer/file.rb

Constant Summary

Constants inherited from Base

Base::MAX_SIZE

Instance Attribute Summary collapse

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#full?

Constructor Details

#initializeFile

Returns a new instance of File.

See Also:



7
8
9
10
11
# File 'lib/fluq/buffer/file.rb', line 7

def initialize(*)
  super
  @file = new_file
  @size = 0
end

Instance Attribute Details

#fileObject (readonly)



4
5
6
# File 'lib/fluq/buffer/file.rb', line 4

def file
  @file
end

Instance Method Details

#closeObject

See Also:



29
30
31
32
# File 'lib/fluq/buffer/file.rb', line 29

def close
  file.close unless file.closed?
  File.unlink(file.path) if File.exists?(file.path)
end

#drainObject

See Also:



35
36
37
38
39
40
41
# File 'lib/fluq/buffer/file.rb', line 35

def drain
  file.close unless file.closed?
  io = File.open(file.path, 'rb', encoding: Encoding::BINARY)
  yield(io)
ensure
  io.close if io
end

#nameObject

See Also:



14
15
16
# File 'lib/fluq/buffer/file.rb', line 14

def name
  @name ||= [super, File.basename(file.path)].join("-")
end

#sizeObject

See Also:



24
25
26
# File 'lib/fluq/buffer/file.rb', line 24

def size
  file.size
end

#write(data) ⇒ Object

See Also:



19
20
21
# File 'lib/fluq/buffer/file.rb', line 19

def write(data)
  file.write(data)
end