Class: Riml::WarningBuffer

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

Constant Summary collapse

BUFFER_WRITE_LOCK =
Mutex.new
WARNING_FMT =
"Warning: %s"

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*warnings) ⇒ WarningBuffer

Returns a new instance of WarningBuffer.



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

def initialize(*warnings)
  @buffer = warnings
end

Class Attribute Details

.streamObject

Returns the value of attribute stream.



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

def stream
  @stream
end

Instance Attribute Details

#bufferObject (readonly)

Returns the value of attribute buffer.



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

def buffer
  @buffer
end

Instance Method Details

#<<(warning) ⇒ Object Also known as: push



22
23
24
# File 'lib/warning_buffer.rb', line 22

def <<(warning)
  BUFFER_WRITE_LOCK.synchronize { buffer << warning }
end

#clearObject



36
37
38
# File 'lib/warning_buffer.rb', line 36

def clear
  BUFFER_WRITE_LOCK.synchronize { buffer.clear }
end

#flushObject



27
28
29
30
31
32
33
34
# File 'lib/warning_buffer.rb', line 27

def flush
  BUFFER_WRITE_LOCK.synchronize do
    stream = self.class.stream
    buffer.each { |w| stream.puts WARNING_FMT % w }
    buffer.clear
    stream.flush
  end
end