Class: Sumac::Message::Object::ExposedChild

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

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) ⇒ ExposedChild

Returns a new instance of ExposedChild.



6
7
8
9
10
# File 'lib/sumac/message/object/exposed_child.rb', line 6

def initialize(connection)
  super
  @parent = nil
  @key = nil
end

Instance Method Details

#invert_orginObject

Raises:



71
72
73
74
75
# File 'lib/sumac/message/object/exposed_child.rb', line 71

def invert_orgin
  raise MessageError unless setup?
  @parent.invert_orgin
  nil
end

#parse_json_structure(json_structure) ⇒ Object

Raises:



12
13
14
15
16
17
18
19
20
21
# File 'lib/sumac/message/object/exposed_child.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'] == 'exposed_child'
  @parent = Exposed.from_json_structure(@connection, json_structure['parent'])
  key = json_structure['key']
  raise MessageError unless key.is_a?(::String) || key.is_a?(::Float) || key.is_a?(::Integer)
  @key = key
  nil
end

#parse_native_object(native_object) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/sumac/message/object/exposed_child.rb', line 23

def parse_native_object(native_object)
  unless native_object.is_a?(RemoteObjectChild) ||
        (native_object.respond_to?(:__sumac_exposed_object__) && native_object.respond_to?(:__parent__))
    raise MessageError
  end
  begin
    native_parent = native_object.__parent__
  rescue
    raise MessageError
  end
  @parent = Exposed.from_native_object(@connection, native_parent)
  begin
    key = native_object.__key__
  rescue
    raise MessageError
  end
  raise unless key.is_a?(::String) || key.is_a?(::Float) || key.is_a?(::Integer)
  @key = key
  nil
end

#to_json_structureObject

Raises:



44
45
46
47
48
49
50
51
52
# File 'lib/sumac/message/object/exposed_child.rb', line 44

def to_json_structure
  raise MessageError unless setup?
  {
    'message_type' => 'object',
    'object_type' => 'exposed_child',
    'parent' => @parent.to_json_structure,
    'key' => @key
  }
end

#to_native_objectObject

Raises:



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/sumac/message/object/exposed_child.rb', line 54

def to_native_object
  raise MessageError unless setup?
  native_parent = @parent.to_native_object
  case native_parent
  when ExposedObject
    begin
      native_child = native_parent.__child__(@key)
    rescue
      raise MessageError
    end
    raise unless native_child.is_a?(ExposedObjectChild)
  when RemoteObject
    native_child = RemoteObjectChild.new(@connection, native_parent, @key)
  end
  native_child
end