Class: Lumberjack::Device::Writer::Buffer

Inherits:
Object
  • Object
show all
Defined in:
lib/lumberjack/device/writer.rb

Overview

Internal buffer to batch writes to the stream.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuffer

Returns a new instance of Buffer.



21
22
23
24
# File 'lib/lumberjack/device/writer.rb', line 21

def initialize
  @values = []
  @size = 0
end

Instance Attribute Details

#sizeObject (readonly)

:nodoc:



19
20
21
# File 'lib/lumberjack/device/writer.rb', line 19

def size
  @size
end

Instance Method Details

#<<(string) ⇒ Object



26
27
28
29
# File 'lib/lumberjack/device/writer.rb', line 26

def <<(string)
  @values << string
  @size += string.size
end

#clearObject



42
43
44
45
# File 'lib/lumberjack/device/writer.rb', line 42

def clear
  @values = []
  @size = 0
end

#empty?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/lumberjack/device/writer.rb', line 31

def empty?
  @values.empty?
end

#pop!Object



35
36
37
38
39
40
# File 'lib/lumberjack/device/writer.rb', line 35

def pop!
  return nil if @values.empty?
  popped = @values
  clear
  popped
end