Class: Pants::Readers::FileReaderConnection

Inherits:
EventMachine::Connection
  • Object
show all
Includes:
LogSwitch::Mixin
Defined in:
lib/pants/readers/file_reader.rb

Overview

This is the EventMachine connection that reads the source file and puts the read data into the data channel so writers can write as they need to.

Instance Method Summary collapse

Constructor Details

#initialize(write_to_channel, starter, stopper) ⇒ FileReaderConnection

Returns a new instance of FileReaderConnection.

Parameters:

  • starter (EventMachine::Callback)

    Gets called when the it’s been fulling initialized.

  • stopper (EventMachine::Callback)

    Gets called when the file-to-read has been fully read.



20
21
22
23
24
# File 'lib/pants/readers/file_reader.rb', line 20

def initialize(write_to_channel, starter, stopper)
  @write_to_channel = write_to_channel
  @stopper = stopper
  @starter = starter
end

Instance Method Details

#post_initObject



26
27
28
# File 'lib/pants/readers/file_reader.rb', line 26

def post_init
  @starter.call
end

#receive_data(data) ⇒ Object

Reads the data and writes it to the data channel.

Parameters:

  • data (String)

    The file data to write to the channel.



33
34
35
36
# File 'lib/pants/readers/file_reader.rb', line 33

def receive_data(data)
  log "<< #{data.size}"
  @write_to_channel << data
end

#unbindObject

Called when the file is done being read.



39
40
41
42
# File 'lib/pants/readers/file_reader.rb', line 39

def unbind
  log "Unbinding, done writing, and notifying the stopper..."
  @stopper.call
end