Class: Pants::Readers::FileReader

Inherits:
BaseReader show all
Includes:
LogSwitch::Mixin
Defined in:
lib/pants/readers/file_reader.rb

Overview

This is the interface for FileReaderConnections. It controls starting and stopping the connection.

Instance Attribute Summary collapse

Attributes inherited from BaseReader

#core_stopper_callback, #write_to_channel, #writers

Instance Method Summary collapse

Methods inherited from BaseReader

#add_seam, #add_writer, #read_object, #remove_writer, #running?, #stop!, #write_to

Constructor Details

#initialize(file_path, core_stopper_callback) ⇒ FileReader

Returns a new instance of FileReader.

Parameters:

  • file_path (String)

    Path to the file to read.

  • core_stopper_callback (EventMachine::Callback)

    The Callback that will get called when #stopper is called. #stopper is called when the whole file has been read and pushed to the channel.



59
60
61
62
63
64
65
66
67
68
# File 'lib/pants/readers/file_reader.rb', line 59

def initialize(file_path, core_stopper_callback)
  log "Initializing #{self.class} with file path '#{file_path}'"
  @read_object = file_path
  @file_path = file_path

  log "Opening file '#{@file_path}'"
  @file = File.open(@file_path, 'r')

  super(core_stopper_callback)
end

Instance Attribute Details

#file_pathString (readonly)

Returns Path to the file that’s being read.

Returns:

  • (String)

    Path to the file that’s being read.



52
53
54
# File 'lib/pants/readers/file_reader.rb', line 52

def file_path
  @file_path
end

Instance Method Details

#startObject

Starts reading the file after all writers have been started.



71
72
73
74
75
76
77
78
# File 'lib/pants/readers/file_reader.rb', line 71

def start
  callback = EM.Callback do
    log "Adding file '#{@file_path}'..."
    EM.attach(@file, FileReaderConnection, @write_to_channel, starter, stopper)
  end

  super(callback)
end