Class: Web::Connection::CallbackBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/web/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&callback) ⇒ CallbackBuffer

Returns a new instance of CallbackBuffer.



433
434
435
436
# File 'lib/web/connection.rb', line 433

def initialize( &callback )
  @callback = callback
  @buffer   = StringIO.new
end

Instance Attribute Details

#callbackObject

Returns the value of attribute callback.



432
433
434
# File 'lib/web/connection.rb', line 432

def callback
  @callback
end

Instance Method Details

#cleanObject



452
453
454
# File 'lib/web/connection.rb', line 452

def clean
  @buffer = StringIO.new
end

#flushObject



438
439
440
441
442
443
444
445
446
# File 'lib/web/connection.rb', line 438

def flush
  result = if @callback
             @callback.call(@buffer.string)
           else
             @buffer.string
           end
  self.clean
  result
end

#get_contentsObject



448
449
450
# File 'lib/web/connection.rb', line 448

def get_contents
  @buffer.string
end