Class: RuVim::Stream::Git
- Inherits:
-
RuVim::Stream
- Object
- RuVim::Stream
- RuVim::Stream::Git
- Defined in:
- lib/ruvim/stream/git.rb
Instance Attribute Summary collapse
-
#io ⇒ Object
Returns the value of attribute io.
-
#thread ⇒ Object
Returns the value of attribute thread.
Attributes inherited from RuVim::Stream
Instance Method Summary collapse
-
#initialize(cmd:, root:, buffer_id:, queue:, stop_handler: nil, ¬ify) ⇒ Git
constructor
A new instance of Git.
- #stop! ⇒ Object
Methods inherited from RuVim::Stream
Constructor Details
#initialize(cmd:, root:, buffer_id:, queue:, stop_handler: nil, ¬ify) ⇒ Git
Returns a new instance of Git.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ruvim/stream/git.rb', line 7 def initialize(cmd:, root:, buffer_id:, queue:, stop_handler: nil, ¬ify) super(stop_handler: stop_handler) @io = nil stream = self @thread = Thread.new do IO.popen(cmd, chdir: root, err: [:child, :out]) do |io| stream.io = io while (chunk = io.read(4096)) queue << { type: :stream_data, buffer_id: buffer_id, data: Buffer.decode_text(chunk) } notify.call end end stream.io = nil queue << { type: :stream_eof, buffer_id: buffer_id } notify.call rescue StandardError => e stream.io = nil queue << { type: :stream_error, buffer_id: buffer_id, error: e..to_s } notify.call end end |
Instance Attribute Details
#io ⇒ Object
Returns the value of attribute io.
5 6 7 |
# File 'lib/ruvim/stream/git.rb', line 5 def io @io end |
#thread ⇒ Object
Returns the value of attribute thread.
5 6 7 |
# File 'lib/ruvim/stream/git.rb', line 5 def thread @thread end |
Instance Method Details
#stop! ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ruvim/stream/git.rb', line 29 def stop! io = @io; @io = nil begin io&.close unless io&.closed? rescue IOError nil end thread = @thread; @thread = nil if thread&.alive? thread.kill thread.join(0.05) end end |