Class: Riml::WarningBuffer
- Inherits:
-
Object
- Object
- Riml::WarningBuffer
- Defined in:
- lib/riml/warning_buffer.rb
Overview
Thread-safe output buffer. Used internally for all Riml warnings. Only one of these objects exists during compile.
Constant Summary collapse
- WRITE_LOCK =
This class acts as a singleton, so no instance-level mutexes are required. This facilitates locking both class and instance methods with a single mutex.
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.
23 24 25 |
# File 'lib/riml/warning_buffer.rb', line 23 def initialize(*warnings) @buffer = warnings end |
Class Attribute Details
.stream ⇒ Object
Returns the value of attribute stream.
15 16 17 |
# File 'lib/riml/warning_buffer.rb', line 15 def stream @stream end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
21 22 23 |
# File 'lib/riml/warning_buffer.rb', line 21 def buffer @buffer end |
Instance Method Details
#<<(warning) ⇒ Object Also known as: push
27 28 29 |
# File 'lib/riml/warning_buffer.rb', line 27 def <<(warning) WRITE_LOCK.synchronize { buffer << warning } end |
#clear ⇒ Object
41 42 43 |
# File 'lib/riml/warning_buffer.rb', line 41 def clear WRITE_LOCK.synchronize { buffer.clear } end |
#flush ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/riml/warning_buffer.rb', line 32 def flush WRITE_LOCK.synchronize do stream = self.class.stream buffer.each { |w| stream.puts WARNING_FMT % w } buffer.clear stream.flush end end |