Class: Neovim::RemoteObject Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/neovim/remote_object.rb

Overview

This class is abstract.

Superclass for all nvim remote objects.

See Also:

Direct Known Subclasses

Buffer, Tabpage, Window

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index, session) ⇒ RemoteObject

Returns a new instance of RemoteObject.



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

def initialize(index, session)
  @index = index
  @session = session
  @api = session.api
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object

Intercept method calls and delegate to appropriate RPC methods.



25
26
27
28
29
30
31
# File 'lib/neovim/remote_object.rb', line 25

def method_missing(method_name, *args)
  if func = @api.function(qualify(method_name))
    func.call(@session, @index, *args)
  else
    super
  end
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



8
9
10
# File 'lib/neovim/remote_object.rb', line 8

def index
  @index
end

Instance Method Details

#==(other) ⇒ Object

Extend == to only look at class and index.



44
45
46
# File 'lib/neovim/remote_object.rb', line 44

def ==(other)
  other.class.equal?(self.class) && @index == other.index
end

#methodsObject

Extend methods to include RPC methods



39
40
41
# File 'lib/neovim/remote_object.rb', line 39

def methods
  super | rpc_methods
end

#respond_to?(method_name) ⇒ Boolean

Extend respond_to? to support RPC methods.

Returns:

  • (Boolean)


34
35
36
# File 'lib/neovim/remote_object.rb', line 34

def respond_to?(method_name)
  super || rpc_methods.include?(method_name.to_sym)
end

#to_msgpack(packer) ⇒ String

Serialize object to MessagePack.

Parameters:

  • packer (MessagePack::Packer)

Returns:

  • (String)


20
21
22
# File 'lib/neovim/remote_object.rb', line 20

def to_msgpack(packer)
  packer.pack(@index)
end