Class: Neovim::Client

Inherits:
Object show all
Includes:
OptionAccess
Defined in:
lib/neovim/client.rb

Defined Under Namespace

Classes: UnknownApiFunction, UnknownApiObjectFunction

Constant Summary collapse

OPTION_PARAM =
nil

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OptionAccess

#get_option, #option_params, #set_option

Constructor Details

#initialize(comm, channel_id) ⇒ Client

Returns a new instance of Client.



25
26
27
28
29
# File 'lib/neovim/client.rb', line 25

def initialize comm, channel_id
  @comm, @channel_id = comm, channel_id
  @functions = {}
  @objfuncs  = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



67
68
69
70
71
# File 'lib/neovim/client.rb', line 67

def method_missing sym, *args
  call_api sym, *args
rescue UnknownApiFunction
  super
end

Class Attribute Details

.strictObject

Returns the value of attribute strict.



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

def strict
  @strict
end

Instance Attribute Details

#channel_idObject (readonly)

Returns the value of attribute channel_id.



23
24
25
# File 'lib/neovim/client.rb', line 23

def channel_id
  @channel_id
end

Instance Method Details

#add_functions(list, prefixes) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/neovim/client.rb', line 35

def add_functions list, prefixes
  list.each { |fn|
    next if fn[ "deprecated_since"] && self.class.strict
    n = fn[ "name"]
    if (b = n.starts_with? "nvim_") then
      @functions[ n[ b...].to_sym] = n
    end
    prefixes.each { |t,p|
      if (b = n.starts_with? p) then
        @objfuncs[ t] ||= {}
        @objfuncs[ t][ n[ b...].to_sym] = n
        break
      end
    }
  }
end

#call_api(name, *args) ⇒ Object



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

def call_api name, *args
  f = @functions[ name.to_sym]
  f or raise UnknownApiFunction, "Function: #{name}"
  @comm.request f, *args
end

#call_obj(obj, name, *args) ⇒ Object



59
60
61
62
63
64
# File 'lib/neovim/client.rb', line 59

def call_obj obj, name, *args
  n = obj.type
  f = @objfuncs[ n.to_sym][ name.to_sym]
  f or raise UnknownApiObjectFunction, "Object: #{n}, Function: #{name}"
  @comm.request f, obj.index, *args
end

#command(arg) ⇒ Object



113
# File 'lib/neovim/client.rb', line 113

def command arg ; call_api :command, arg ; end

#evaluate(expr) ⇒ Object



115
# File 'lib/neovim/client.rb', line 115

def evaluate expr ; call_api :eval, expr ; end

#functionsObject



86
87
88
# File 'lib/neovim/client.rb', line 86

def functions
  @functions.keys
end

#has_obj_function?(obj, name) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/neovim/client.rb', line 91

def has_obj_function? obj, name
  @objfuncs[ obj.type][ name.to_sym].to_bool
end

#inspectObject



31
32
33
# File 'lib/neovim/client.rb', line 31

def inspect
  "#<#{self.class} #@channel_id>"
end

#message(str) ⇒ Object



104
105
106
107
# File 'lib/neovim/client.rb', line 104

def message str
  call_api :out_write, str
  str.end_with? $/ or call_api :out_write, $/
end

#methods(regular = true) ⇒ Object



80
81
82
83
84
# File 'lib/neovim/client.rb', line 80

def methods regular = true
  s = super
  s |= @functions.keys if regular
  s
end

#obj_classesObject



95
96
97
# File 'lib/neovim/client.rb', line 95

def obj_classes
  RemoteObject.subclasses.select { |c| @objfuncs[ c.type] rescue nil }
end

#obj_functions(obj) ⇒ Object



99
100
101
# File 'lib/neovim/client.rb', line 99

def obj_functions obj
  @objfuncs[ obj.type].keys
end

#respond_to_missing?(sym, priv = nil) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
76
77
78
# File 'lib/neovim/client.rb', line 73

def respond_to_missing? sym, priv = nil
  # Be aware that calling a proc (our handlers) with a single argument
  # asks whether that argument is an array. In case it is a Client object,
  # we end up here with +sym = to_ary+.
  @functions[ sym.to_sym].to_bool
end