Class: Neovim::Connection Private

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/neovim/connection.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary

Constants included from Logging

Logging::TIMESTAMP_FORMAT

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

included, logger, logger=

Constructor Details

#initialize(rd, wr) ⇒ Connection

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Connection.



34
35
36
37
38
39
40
# File 'lib/neovim/connection.rb', line 34

def initialize(rd, wr)
  @rd, @wr = [rd, wr].each { |io| io.binmode.sync = true }

  @unpacker = MessagePack::Unpacker.new(@rd)
  @packer = MessagePack::Packer.new(@wr)
  @running = false
end

Class Method Details

.child(_argv) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
23
24
25
26
27
28
# File 'lib/neovim/connection.rb', line 20

def self.child(_argv)
  argv = _argv.include?("--embed") ? _argv : _argv + ["--embed"]

  io = ::IO.popen(argv, "rb+").tap do |_io|
    Process.detach(_io.pid)
  end

  new(io, io)
end

.stdioObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



30
31
32
# File 'lib/neovim/connection.rb', line 30

def self.stdio
  new(STDIN, STDOUT)
end

.tcp(host, port) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
13
# File 'lib/neovim/connection.rb', line 10

def self.tcp(host, port)
  socket = Socket.tcp(host, port)
  new(socket, socket)
end

.unix(path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



15
16
17
18
# File 'lib/neovim/connection.rb', line 15

def self.unix(path)
  socket = Socket.unix(path)
  new(socket, socket)
end

Instance Method Details

#closeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



60
61
62
63
64
65
66
67
# File 'lib/neovim/connection.rb', line 60

def close
  [@rd, @wr].each do |io|
    begin
      io.close
    rescue ::IOError
    end
  end
end

#readObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



47
48
49
50
51
# File 'lib/neovim/connection.rb', line 47

def read
  @unpacker.read.tap do |object|
    log(:debug) { {object: object} }
  end
end

#register_type(id, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
56
57
58
# File 'lib/neovim/connection.rb', line 53

def register_type(id, &block)
  @unpacker.register_type(id) do |data|
    index = MessagePack.unpack(data)
    block.call(index)
  end
end

#write(object) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



42
43
44
45
# File 'lib/neovim/connection.rb', line 42

def write(object)
  log(:debug) { {object: object} }
  @packer.write(object).flush
end