Class: PuppetEditorServices::Protocol::JsonRPCMessages::ResponseMessage
- Inherits:
-
Message
- Object
- Message
- PuppetEditorServices::Protocol::JsonRPCMessages::ResponseMessage
- 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
-
#error ⇒ Object
Returns the value of attribute error.
-
#id ⇒ Object
Returns the value of attribute id.
-
#is_successful ⇒ Object
is_successful is special.
-
#result ⇒ Object
Returns the value of attribute result.
Attributes inherited from Message
Instance Method Summary collapse
- #from_h!(value) ⇒ Object
-
#initialize(initial_hash = nil) ⇒ ResponseMessage
constructor
A new instance of ResponseMessage.
- #to_h ⇒ Object
Methods inherited from Message
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
#error ⇒ Object
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 |
#id ⇒ Object
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_successful ⇒ Object
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 |
#result ⇒ Object
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_h ⇒ Object
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 |