Class: Covet::LogCollection
- Inherits:
-
Object
- Object
- Covet::LogCollection
- Defined in:
- lib/covet/log_collection.rb
Instance Attribute Summary collapse
-
#flushes ⇒ Object
readonly
Returns the value of attribute flushes.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #<<(logs) ⇒ Object (also: #append)
- #finish! ⇒ Object
-
#initialize(options = {}) ⇒ LogCollection
constructor
A new instance of LogCollection.
Constructor Details
#initialize(options = {}) ⇒ LogCollection
7 8 9 10 11 12 13 |
# File 'lib/covet/log_collection.rb', line 7 def initialize( = {}) @bufsize = [:bufsize] || 100 # max log buffer size to keep in memory @log_file = LogFile.new(:filename => [:filename], :mode => 'w') @buf = [] @flushes = 0 @size = 0 end |
Instance Attribute Details
#flushes ⇒ Object (readonly)
Returns the value of attribute flushes.
5 6 7 |
# File 'lib/covet/log_collection.rb', line 5 def flushes @flushes end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
5 6 7 |
# File 'lib/covet/log_collection.rb', line 5 def size @size end |
Instance Method Details
#<<(logs) ⇒ Object Also known as: append
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/covet/log_collection.rb', line 16 def <<(logs) unless Array === logs raise TypeError, "expecting Array, got #{logs.class}" end @buf << logs if @buf.size == @bufsize flush! end @size += 1 true end |
#finish! ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/covet/log_collection.rb', line 29 def finish! if @flushes == 0 && @buf.size == 0 return # avoid writing to file if no collections end flush! if @buf.any? @log_file.write_end true end |