Class: Neovim::Remote::Message

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

Direct Known Subclasses

Notification, Request, Response

Defined Under Namespace

Classes: Notification, Request, Response

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Message

Returns a new instance of Message.



37
38
39
40
# File 'lib/neovim/remote.rb', line 37

def initialize *args
  z = self.class::KEYS.zip args
  @cont = z.inject Hash.new do |c,(h,k)| c[h] = k ; c end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



51
52
53
# File 'lib/neovim/remote.rb', line 51

def method_missing sym, *args
  if @cont.key? sym then @cont[ sym] else super end
end

Class Method Details

.find(id) ⇒ Object



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

def find id
  @subh[ id] ||= @subs.find { |c| c::ID == id }
end

.from_array(ary) ⇒ Object



21
22
23
24
25
26
# File 'lib/neovim/remote.rb', line 21

def from_array ary
  kind, *payload = *ary
  klass = find kind
  klass or raise "No message type for id #{kind.inspect}"
  klass[ *payload]
end

.inherited(cls) ⇒ Object



28
# File 'lib/neovim/remote.rb', line 28

def inherited cls ; @subs.push cls ; end

Instance Method Details

#fieldsObject



65
# File 'lib/neovim/remote.rb', line 65

def fields ; @cont.fetch_values *self.class::KEYS ; end

#inspectObject



42
43
44
# File 'lib/neovim/remote.rb', line 42

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

#methods(*args) ⇒ Object



59
60
61
# File 'lib/neovim/remote.rb', line 59

def methods *args
  super.concat @cont.keys
end

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

Returns:

  • (Boolean)


55
56
57
# File 'lib/neovim/remote.rb', line 55

def respond_to_missing? sym, priv = nil
  @cont.key? sym.to_sym
end

#to_aObject



67
68
69
# File 'lib/neovim/remote.rb', line 67

def to_a
  [self.class::ID, *fields]
end

#to_hObject



63
# File 'lib/neovim/remote.rb', line 63

def to_h ; @cont ; end

#to_sObject



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

def to_s
  j = @cont.map { |k,v| "#{k}:#{v}" if v }.compact.join ","
  "#{self.class.plain_name}(#{j})"
end