Module: PuppetEditorServices::Protocol::JsonRPCMessages

Defined in:
lib/puppet_editor_services/protocol/json_rpc_messages.rb

Defined Under Namespace

Classes: Message, NotificationMessage, RequestMessage, ResponseMessage

Class Method Summary collapse

Class Method Details

.new_notification(method_name, params) ⇒ Object



191
192
193
# File 'lib/puppet_editor_services/protocol/json_rpc_messages.rb', line 191

def self.new_notification(method_name, params)
  NotificationMessage.new.from_h!('method' => method_name, 'params' => params)
end

.new_request(id, method_name, params) ⇒ Object



195
196
197
# File 'lib/puppet_editor_services/protocol/json_rpc_messages.rb', line 195

def self.new_request(id, method_name, params)
  RequestMessage.new.from_h!('id' => id, 'method' => method_name, 'params' => params)
end

.reply_error(request, code, message) ⇒ Object



167
168
169
# File 'lib/puppet_editor_services/protocol/json_rpc_messages.rb', line 167

def self.reply_error(request, code, message)
  reply_error_by_id(request.id, code, message)
end

.reply_error_by_id(id, code, message) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
# File 'lib/puppet_editor_services/protocol/json_rpc_messages.rb', line 171

def self.reply_error_by_id(id, code, message)
  # Note - Strictly speaking the error should be typed object, however as this hidden behind
  # this method it's easier to just pass in a known hash construct
  ResponseMessage.new.from_h!(
    'id' => id,
    'error' => {
      'code' => code,
      'message' => message
    }
  )
end

.reply_method_not_found(request, message = nil) ⇒ Object



183
184
185
186
187
188
189
# File 'lib/puppet_editor_services/protocol/json_rpc_messages.rb', line 183

def self.reply_method_not_found(request, message = nil)
  reply_error(
    request,
    ::PuppetEditorServices::Protocol::JsonRPC::CODE_METHOD_NOT_FOUND,
    message || ::PuppetEditorServices::Protocol::JsonRPC::MSG_METHOD_NOT_FOUND
  )
end

.reply_result(request, result) ⇒ Object

Static message generators



163
164
165
# File 'lib/puppet_editor_services/protocol/json_rpc_messages.rb', line 163

def self.reply_result(request, result)
  ResponseMessage.new.from_h!('id' => request.id, 'result' => result)
end