Class: Cuboid::Support::Buffer::Base
- Includes:
- Mixins::Observable
- Defined in:
- lib/cuboid/support/buffer/base.rb
Overview
Base buffer class to be extended by more specialised implementation.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#max_size ⇒ Integer
readonly
Maximum buffer size.
Instance Method Summary collapse
- #<<(obj) ⇒ Object (also: #push)
- #batch_push(list) ⇒ Object
-
#empty? ⇒ Bool
‘true` if the buffer is empty, `false` otherwise.
-
#flush ⇒ Object
Current buffer.
-
#full? ⇒ Bool
‘true` if the buffer is full, `false` otherwise.
-
#initialize(max_size = nil, type = Array) ⇒ Base
constructor
A new instance of Base.
- #on_batch_push(&block) ⇒ Object
- #on_flush(&block) ⇒ Object
- #on_push(&block) ⇒ Object
-
#size ⇒ Integer
Number of object in the buffer.
Methods included from Mixins::Observable
Methods included from Utilities
#available_port, available_port_mutex, #bytes_to_kilobytes, #bytes_to_megabytes, #caller_name, #caller_path, #exception_jail, #generate_token, #hms_to_seconds, #port_available?, #rand_port, #random_seed, #regexp_array_match, #remove_constants, #seconds_to_hms
Methods included from UI::Output
#error_buffer, initialize, #log_error, #output_provider_file, #print_bad, #print_debug, #print_error, #print_info, #print_line, #print_ok, #print_status, #print_verbose, #reroute_to_file, #reroute_to_file?
Methods included from UI::OutputInterface
Methods included from UI::OutputInterface::Personalization
Methods included from UI::OutputInterface::Controls
#debug?, #debug_level, #debug_level_1?, #debug_level_2?, #debug_level_3?, #debug_level_4?, #debug_off, #debug_on, initialize, #verbose?, #verbose_off, #verbose_on
Methods included from UI::OutputInterface::ErrorLogging
#error_logfile, #has_error_log?, initialize, #set_error_logfile
Methods included from UI::OutputInterface::Implemented
#print_debug_backtrace, #print_debug_exception, #print_debug_level_1, #print_debug_level_2, #print_debug_level_3, #print_debug_level_4, #print_error_backtrace, #print_exception
Methods included from UI::OutputInterface::Abstract
#output_provider_file, #print_bad, #print_debug, #print_error, #print_info, #print_line, #print_ok, #print_status, #print_verbose
Constructor Details
Instance Attribute Details
#max_size ⇒ Integer (readonly)
Returns Maximum buffer size.
25 26 27 |
# File 'lib/cuboid/support/buffer/base.rb', line 25 def max_size @max_size end |
Instance Method Details
#<<(obj) ⇒ Object Also known as: push
Calls #on_push blocks with the given object and pushes an object to the buffer.
42 43 44 45 46 |
# File 'lib/cuboid/support/buffer/base.rb', line 42 def <<( obj ) notify_on_push obj @buffer << obj self end |
#batch_push(list) ⇒ Object
Calls #on_batch_push blocks with the given list and merges the buffer with the contents of a list.
54 55 56 57 58 |
# File 'lib/cuboid/support/buffer/base.rb', line 54 def batch_push( list ) notify_on_batch_push list @buffer |= list self end |
#empty? ⇒ Bool
Returns ‘true` if the buffer is empty, `false` otherwise.
68 69 70 |
# File 'lib/cuboid/support/buffer/base.rb', line 68 def empty? @buffer.empty? end |
#flush ⇒ Object
Calls #on_flush blocks with the buffer and then empties it.
Returns current buffer.
81 82 83 84 85 86 87 |
# File 'lib/cuboid/support/buffer/base.rb', line 81 def flush buffer = @buffer.dup notify_on_flush buffer buffer ensure @buffer.clear end |
#full? ⇒ Bool
Returns ‘true` if the buffer is full, `false` otherwise.
74 75 76 |
# File 'lib/cuboid/support/buffer/base.rb', line 74 def full? !!(max_size && size >= max_size) end |
#on_batch_push(&block) ⇒ Object
18 |
# File 'lib/cuboid/support/buffer/base.rb', line 18 advertise :on_batch_push |
#on_flush(&block) ⇒ Object
22 |
# File 'lib/cuboid/support/buffer/base.rb', line 22 advertise :on_flush |
#size ⇒ Integer
Returns Number of object in the buffer.
62 63 64 |
# File 'lib/cuboid/support/buffer/base.rb', line 62 def size @buffer.size end |