Class: Neovim::RemoteModule

Inherits:
Object show all
Includes:
Logging
Defined in:
lib/neovim/remote_module.rb,
lib/neovim/remote_module/dsl.rb

Defined Under Namespace

Classes: DSL

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(handlers) ⇒ RemoteModule

Returns a new instance of RemoteModule.



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

def initialize(handlers)
  @handlers = handlers
end

Class Method Details

.from_config_block(&block) ⇒ Object



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

def self.from_config_block(&block)
  new(DSL::new(&block).handlers)
end

Instance Method Details

#startObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/neovim/remote_module.rb', line 19

def start
  event_loop = EventLoop.stdio
  session = Session.new(event_loop)
  client = nil

  session.run do |message|
    case message
    when Message::Request
      begin
        client ||= Client.from_event_loop(event_loop, session)
        args = message.arguments.flatten(1)

        @handlers[message.method_name].call(client, *args).tap do |rv|
          session.respond(message.id, rv, nil) if message.sync?
        end
      rescue => e
        log_exception(:error, e, __method__)
        session.respond(message.id, nil, e.message) if message.sync?
      end
    end
  end
end