Class: Neovim::RemoteModule::DSL

Inherits:
BasicObject
Defined in:
lib/neovim/remote_module/dsl.rb

Overview

The DSL exposed in Neovim.start_remote blocks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ DSL

Returns a new instance of DSL.



9
10
11
12
13
14
15
16
17
# File 'lib/neovim/remote_module/dsl.rb', line 9

def initialize(&block)
  @handlers = ::Hash.new do |h, name|
    h[name] = ::Proc.new do |_, *|
      raise NotImplementedError, "undefined handler #{name.inspect}"
    end
  end

  block&.call(self)
end

Instance Attribute Details

#handlersObject (readonly)



7
8
9
# File 'lib/neovim/remote_module/dsl.rb', line 7

def handlers
  @handlers
end

Instance Method Details

#register_handler(name, &block) ⇒ Object

Define an RPC handler for use in remote modules.

Parameters:

  • name (String)

    The handler name.

  • block (Proc)

    The body of the handler.



23
24
25
26
27
# File 'lib/neovim/remote_module/dsl.rb', line 23

def register_handler(name, &block)
  @handlers[name.to_s] = ::Proc.new do |client, *args|
    block.call(client, *args)
  end
end