Class: Sumac::Message::Object::NativeException
- Inherits:
-
Base
show all
- Defined in:
- lib/sumac/message/object/native_exception.rb
Instance Method Summary
collapse
Methods inherited from Base
from_json_structure, from_native_object
from_json_structure, from_native_object
from_json, #to_json
Constructor Details
Returns a new instance of NativeException.
6
7
8
9
10
|
# File 'lib/sumac/message/object/native_exception.rb', line 6
def initialize(connection)
super
@type = nil
@message = nil
end
|
Instance Method Details
#parse_json_structure(json_structure) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/sumac/message/object/native_exception.rb', line 12
def parse_json_structure(json_structure)
raise MessageError unless json_structure.is_a?(::Hash) &&
json_structure['message_type'] == 'object' &&
json_structure['object_type'] == 'native_exception'
raise MessageError unless json_structure['type'].is_a?(::String)
@type = json_structure['type']
if json_structure['message']
raise MessageError unless json_structure['message'].is_a?(::String)
@message = json_structure['message']
end
nil
end
|
#parse_native_object(native_object) ⇒ Object
25
26
27
28
29
30
|
# File 'lib/sumac/message/object/native_exception.rb', line 25
def parse_native_object(native_object)
raise MessageError unless native_object.kind_of?(::Exception)
@type = native_object.class.to_s
@message = native_object.message
nil
end
|
#to_json_structure ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/sumac/message/object/native_exception.rb', line 32
def to_json_structure
raise MessageError unless setup?
{
'message_type' => 'object',
'object_type' => 'native_exception',
'type' => @type,
'message' => @message
}
end
|
#to_native_object ⇒ Object
42
43
44
45
|
# File 'lib/sumac/message/object/native_exception.rb', line 42
def to_native_object
raise MessageError unless setup?
NativeError.new(@type, @message)
end
|