Class: Sumac::Message::Object::Exception

Inherits:
Base show all
Defined in:
lib/sumac/message/object/exception.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

from_json_structure, from_native_object

Methods inherited from Sumac::Message::Object

from_json_structure, from_native_object

Methods inherited from Sumac::Message

from_json, #to_json

Constructor Details

#initialize(connection) ⇒ Exception

Returns a new instance of Exception.



16
17
18
19
20
# File 'lib/sumac/message/object/exception.rb', line 16

def initialize(connection)
  super
  @type = nil
  @message = nil
end

Class Method Details

.mapObject



6
7
8
9
10
11
12
13
14
# File 'lib/sumac/message/object/exception.rb', line 6

def self.map
  @map ||=
    [
      ['no_method_exception', NoMethodError],
      ['argument_exception', ArgumentError],
      ['stale_object_exception', StaleObjectError],
      ['unexposable_object_exception', UnexposableObjectError]
    ]
end

Instance Method Details

#parse_json_structure(json_structure) ⇒ Object

Raises:



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sumac/message/object/exception.rb', line 22

def parse_json_structure(json_structure)
  raise MessageError unless json_structure.is_a?(::Hash) &&
    json_structure['message_type'] == 'object' &&
    json_structure['object_type'] == 'exception'
  raise MessageError if self.class.map.assoc(json_structure['type']) == nil
  @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

Raises:



35
36
37
38
39
40
# File 'lib/sumac/message/object/exception.rb', line 35

def parse_native_object(native_object)
  raise MessageError if self.class.map.rassoc(native_object.class) == nil
  @type = self.class.map.rassoc(native_object.class)[0]
  @message = native_object.message
  nil
end

#to_json_structureObject

Raises:



42
43
44
45
46
47
48
49
50
# File 'lib/sumac/message/object/exception.rb', line 42

def to_json_structure
  raise MessageError unless setup?
  {
    'message_type' => 'object',
    'object_type' => 'exception',
    'type' => @type,
    'message' => @message
  }
end

#to_native_objectObject

Raises:



52
53
54
55
# File 'lib/sumac/message/object/exception.rb', line 52

def to_native_object
  raise MessageError unless setup?
  self.class.map.assoc(@type)[1].new(@message)
end