Class: Thrash
- Inherits:
-
Object
- Object
- Thrash
- Defined in:
- lib/thrash/thrash.rb,
lib/thrash/version.rb
Defined Under Namespace
Modules: Version
Instance Method Summary collapse
-
#add(bucket, obj) ⇒ Object
(also: #write)
add object to bucket check if bucket is full and if it is write out and flush.
-
#finalize ⇒ Object
write and flush remaining buckets.
-
#initialize(args = {}) ⇒ Thrash
constructor
A new instance of Thrash.
Constructor Details
#initialize(args = {}) ⇒ Thrash
Returns a new instance of Thrash.
3 4 5 6 7 |
# File 'lib/thrash/thrash.rb', line 3 def initialize(args={}) # number of items to keep in buffer before writing @buffer_max = args[:buffer_max] || 100_000 create_buffer! end |
Instance Method Details
#add(bucket, obj) ⇒ Object Also known as: write
add object to bucket check if bucket is full and if it is write out and flush
12 13 14 15 |
# File 'lib/thrash/thrash.rb', line 12 def add(bucket, obj) @buffer[bucket] << obj check_and_write bucket end |
#finalize ⇒ Object
write and flush remaining buckets
21 22 23 24 25 26 27 |
# File 'lib/thrash/thrash.rb', line 21 def finalize @buffer.each_key do |bucket| write_and_flush bucket end clear_buffer! nil end |