Class: Mockingbird::Commands::Pipe
- Defined in:
- lib/mockingbird/commands.rb
Instance Attribute Summary
Attributes inherited from Command
Instance Method Summary collapse
-
#initialize(string_or_io, delay = nil) ⇒ Pipe
constructor
A new instance of Pipe.
- #run(conn) ⇒ Object
Methods inherited from Command
Constructor Details
#initialize(string_or_io, delay = nil) ⇒ Pipe
Returns a new instance of Pipe.
99 100 101 102 103 104 105 106 |
# File 'lib/mockingbird/commands.rb', line 99 def initialize(string_or_io,delay=nil) if string_or_io.kind_of?(String) @io = File.open(string_or_io,'r') else @io = string_or_io end @delay = delay end |
Instance Method Details
#run(conn) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/mockingbird/commands.rb', line 108 def run(conn) unless io.eof? chunk = io.readline conn.send_chunk(chunk) if delay EM.add_timer(delay) { run(conn) } else EM.schedule { run(conn) } end else # Reset for future calls io.rewind advance(conn) end end |