Class: Cuboid::Support::Buffer::AutoFlush

Inherits:
Base show all
Defined in:
lib/cuboid/support/buffer/autoflush.rb

Overview

A buffer implementation which flushes itself when it gets full or a number of push attempts is reached between flushes.

Author:

Instance Attribute Summary collapse

Attributes inherited from Base

#max_size

Instance Method Summary collapse

Methods inherited from Base

#empty?, #full?, #on_batch_push, #on_flush, #on_push, #size

Methods included from Mixins::Observable

included

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

initialize

Methods included from UI::OutputInterface::Personalization

#included

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

#initialize(max_size = nil, max_pushes = nil, type = Array) ⇒ AutoFlush

Returns a new instance of AutoFlush.

Parameters:

  • max_size (Integer) (defaults to: nil)

    Maximum buffer size – a flush will be triggered when that limit is reached.

  • max_pushes (Integer) (defaults to: nil)

    Maximum number of pushes between flushes.

  • type (#<<, #|, #clear, #size, #empty?) (defaults to: Array)

    Internal storage class to use.



19
20
21
22
23
24
# File 'lib/cuboid/support/buffer/autoflush.rb', line 19

def initialize( max_size = nil, max_pushes = nil, type = Array )
    super( max_size, type )

    @max_pushes = max_pushes
    @pushes     = 0
end

Instance Attribute Details

#max_pushesObject (readonly)

Returns the value of attribute max_pushes.



10
11
12
# File 'lib/cuboid/support/buffer/autoflush.rb', line 10

def max_pushes
  @max_pushes
end

Instance Method Details

#<<(*args) ⇒ Object



26
27
28
29
30
# File 'lib/cuboid/support/buffer/autoflush.rb', line 26

def <<( *args )
    super( *args )
ensure
    handle_push
end

#batch_push(*args) ⇒ Object



32
33
34
35
36
# File 'lib/cuboid/support/buffer/autoflush.rb', line 32

def batch_push( *args )
    super( *args )
ensure
    handle_push
end

#flushObject



38
39
40
41
42
# File 'lib/cuboid/support/buffer/autoflush.rb', line 38

def flush
    super
ensure
    @pushes = 0
end