Class: Pants::Writers::BaseWriter
- Inherits:
-
Object
- Object
- Pants::Writers::BaseWriter
- Defined in:
- lib/pants/writers/base_writer.rb
Overview
Provides conventions for creating your own writer that can stop and start safely.
You should also consider adding attr_readers/methods for attributes that are differentiators from other writers of the same type. This will allow readers to more easily remove your writer from them.
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(read_from_channel) ⇒ BaseWriter
constructor
A new instance of BaseWriter.
-
#running? ⇒ Boolean
Is the Writer writing data?.
-
#start ⇒ Object
This method must be redefined in a child class.
-
#starter ⇒ EventMachine::Callback
This should get called with #call after the writer is sure to be up and running, ready for accepting data.
-
#stop ⇒ Object
This method must be redefined in a child class.
-
#stopper ⇒ EventMachine::Callback
This should get called with #call after the writer is done writing out the data in its channel.
-
#write_object ⇒ String
A String that identifies what the writer is writing to.
Constructor Details
#initialize(read_from_channel) ⇒ BaseWriter
Returns a new instance of BaseWriter.
18 19 20 21 22 23 24 |
# File 'lib/pants/writers/base_writer.rb', line 18 def initialize(read_from_channel) @running = false @read_from_channel = read_from_channel @write_object ||= nil @starter = nil @stopper = nil end |
Instance Method Details
#running? ⇒ Boolean
Returns Is the Writer writing data?.
68 69 70 |
# File 'lib/pants/writers/base_writer.rb', line 68 def running? @running end |
#start ⇒ Object
This method must be redefined in a child class. The reader that this writer is tied to will call this before it starts reading.
28 29 30 |
# File 'lib/pants/writers/base_writer.rb', line 28 def start warn "You haven't defined a start method--are you sure this writer does something?" end |
#starter ⇒ EventMachine::Callback
This should get called with #call after the writer is sure to be up and running, ready for accepting data.
54 55 56 |
# File 'lib/pants/writers/base_writer.rb', line 54 def starter @starter ||= EM.Callback { @running = true } end |
#stop ⇒ Object
This method must be redefined in a child class. The reader that this writer is tied to will call this when it’s done reading whatever it’s reading.
35 36 37 |
# File 'lib/pants/writers/base_writer.rb', line 35 def stop warn "You haven't defined a stop method--are you sure you're cleaning up?" end |
#stopper ⇒ EventMachine::Callback
This should get called with #call after the writer is done writing out the data in its channel.
63 64 65 |
# File 'lib/pants/writers/base_writer.rb', line 63 def stopper @stopper ||= EM.Callback { @running = false } end |
#write_object ⇒ String
Returns A String that identifies what the writer is writing to. This is simply used for displaying info to the user.
41 42 43 44 45 46 47 |
# File 'lib/pants/writers/base_writer.rb', line 41 def write_object if @write_object @write_object else warn "No write_object info has been defined for this writer." end end |