Class: Xi::ErrorLog
Instance Attribute Summary collapse
-
#max_msgs ⇒ Object
Returns the value of attribute max_msgs.
-
#more_errors ⇒ Object
(also: #more_errors?)
readonly
Returns the value of attribute more_errors.
Instance Method Summary collapse
- #<<(msg) ⇒ Object
- #each ⇒ Object
-
#initialize(max_msgs: 6) ⇒ ErrorLog
constructor
A new instance of ErrorLog.
Constructor Details
#initialize(max_msgs: 6) ⇒ ErrorLog
Returns a new instance of ErrorLog.
12 13 14 15 16 17 18 |
# File 'lib/xi/error_log.rb', line 12 def initialize(max_msgs: 6) @max_msgs = max_msgs @mutex = Mutex.new @errors = [] @more_errors = false end |
Instance Attribute Details
#max_msgs ⇒ Object
Returns the value of attribute max_msgs.
8 9 10 |
# File 'lib/xi/error_log.rb', line 8 def max_msgs @max_msgs end |
#more_errors ⇒ Object (readonly) Also known as: more_errors?
Returns the value of attribute more_errors.
9 10 11 |
# File 'lib/xi/error_log.rb', line 9 def more_errors @more_errors end |
Instance Method Details
#<<(msg) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/xi/error_log.rb', line 20 def <<(msg) @mutex.synchronize do @errors.unshift(msg) unless @errors.include?(msg) if @errors.size >= @max_msgs @errors.slice!(@max_msgs) @more_errors = true end end end |
#each ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/xi/error_log.rb', line 30 def each return enum_for(:each) unless block_given? msgs = @mutex.synchronize do res = @errors.dup @errors.clear @more_errors = false res end while !msgs.empty? yield msgs.shift end end |