Class: Pants::Readers::FileReader
- Inherits:
-
BaseReader
- Object
- BaseReader
- Pants::Readers::FileReader
- 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
-
#file_path ⇒ String
readonly
Path to the file that’s being read.
Attributes inherited from BaseReader
#core_stopper_callback, #write_to_channel, #writers
Instance Method Summary collapse
-
#initialize(file_path, core_stopper_callback) ⇒ FileReader
constructor
A new instance of FileReader.
-
#start ⇒ Object
Starts reading the file after all writers have been started.
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.
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_path ⇒ String (readonly)
Returns 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
#start ⇒ Object
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 |