Class: Riml::WarningBuffer
- Inherits:
-
Object
- Object
- Riml::WarningBuffer
- Defined in:
- lib/warning_buffer.rb
Constant Summary collapse
- BUFFER_WRITE_LOCK =
Mutex.new
- WARNING_FMT =
"Warning: %s"
Class Attribute Summary collapse
-
.stream ⇒ Object
Returns the value of attribute stream.
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
Instance Method Summary collapse
- #<<(warning) ⇒ Object (also: #push)
- #clear ⇒ Object
- #flush ⇒ Object
-
#initialize(*warnings) ⇒ WarningBuffer
constructor
A new instance of WarningBuffer.
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
.stream ⇒ Object
Returns the value of attribute stream.
10 11 12 |
# File 'lib/warning_buffer.rb', line 10 def stream @stream end |
Instance Attribute Details
#buffer ⇒ Object (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 |
#clear ⇒ Object
36 37 38 |
# File 'lib/warning_buffer.rb', line 36 def clear BUFFER_WRITE_LOCK.synchronize { buffer.clear } end |
#flush ⇒ Object
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 |