Class: Neovim::Connection Private

Inherits:
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.



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

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

  @unpacker = MessagePack::Unpacker.new(@rd)
  @packer = MessagePack::Packer.new(@wr)
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
# File 'lib/neovim/connection.rb', line 20

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

  io = ::IO.popen(argv, "rb+")
  Process.detach(io.pid)

  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.



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

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.



64
65
66
67
68
69
70
71
# File 'lib/neovim/connection.rb', line 64

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

#flushObject

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.



52
53
54
55
# File 'lib/neovim/connection.rb', line 52

def flush
  @packer.flush
  self
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.



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

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

#register_type(id) ⇒ 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.



57
58
59
60
61
62
# File 'lib/neovim/connection.rb', line 57

def register_type(id)
  @unpacker.register_type(id) do |data|
    index = MessagePack.unpack(data)
    yield 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.



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

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