Class: PuppetEditorServices::Protocol::JsonRPCMessages::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_editor_services/protocol/json_rpc_messages.rb

Overview

Protocol message primitives

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(initial_hash = nil) ⇒ Message

Returns a new instance of Message.



12
13
14
15
# File 'lib/puppet_editor_services/protocol/json_rpc_messages.rb', line 12

def initialize(initial_hash = nil)
  @jsonrpc = ::PuppetEditorServices::Protocol::JsonRPC::JSONRPC_VERSION
  from_h!(initial_hash)
end

Instance Attribute Details

#jsonrpcObject

Returns the value of attribute jsonrpc.



10
11
12
# File 'lib/puppet_editor_services/protocol/json_rpc_messages.rb', line 10

def jsonrpc
  @jsonrpc
end

Instance Method Details

#from_h!(value) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/puppet_editor_services/protocol/json_rpc_messages.rb', line 17

def from_h!(value)
  return self if value.nil? || value.empty?

  # jsonrpc is a little special.  Don't override it with nil. This
  # allows `.new.from_h!(..)` to use the default without knowing exactly
  # what version is used.
  self.jsonrpc = value['jsonrpc'] unless value['jsonrpc'].nil?
  self
end

#to_hObject



31
32
33
34
35
# File 'lib/puppet_editor_services/protocol/json_rpc_messages.rb', line 31

def to_h
  {
    'jsonrpc' => jsonrpc
  }
end

#to_json(*options) ⇒ Object



27
28
29
# File 'lib/puppet_editor_services/protocol/json_rpc_messages.rb', line 27

def to_json(*options)
  to_h.to_json(options)
end