Class: PuppetEditorServices::Protocol::JsonRPCMessages::ResponseMessage

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

Overview

/**

  * The error object in case a request fails.
  */
error?: ResponseError<any>;

}

Instance Attribute Summary collapse

Attributes inherited from Message

#jsonrpc

Instance Method Summary collapse

Methods inherited from Message

#to_json

Constructor Details

#initialize(initial_hash = nil) ⇒ ResponseMessage

Returns a new instance of ResponseMessage.



133
134
135
# File 'lib/puppet_editor_services/protocol/json_rpc_messages.rb', line 133

def initialize(initial_hash = nil)
  super
end

Instance Attribute Details

#errorObject

Returns the value of attribute error.



128
129
130
# File 'lib/puppet_editor_services/protocol/json_rpc_messages.rb', line 128

def error
  @error
end

#idObject

Returns the value of attribute id.



128
129
130
# File 'lib/puppet_editor_services/protocol/json_rpc_messages.rb', line 128

def id
  @id
end

#is_successfulObject

is_successful is special. It changes based on deserialising from hash or can be manually set. This affects serialisation



131
132
133
# File 'lib/puppet_editor_services/protocol/json_rpc_messages.rb', line 131

def is_successful
  @is_successful
end

#resultObject

Returns the value of attribute result.



128
129
130
# File 'lib/puppet_editor_services/protocol/json_rpc_messages.rb', line 128

def result
  @result
end

Instance Method Details

#from_h!(value) ⇒ Object



137
138
139
140
141
142
143
144
145
# File 'lib/puppet_editor_services/protocol/json_rpc_messages.rb', line 137

def from_h!(value)
  value = {} if value.nil?
  super
  self.id = value['id']
  self.result = value['result']
  self.error = value['error']
  self.is_successful = value.key?('result')
  self
end

#to_hObject



147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/puppet_editor_services/protocol/json_rpc_messages.rb', line 147

def to_h
  hash = { 'id' => id }
  # Ref - https://www.jsonrpc.org/specification#response_object
  if is_successful
    # Succesful responses must ALWAYS have the result key, even if it's null.
    hash['result'] = result
  else
    # Error responses must ALWAYS have the error key
    # TODO: The RPC spec says error MUST be an Error object, not nil.
    hash['error'] = error
  end
  super.merge(hash)
end