Class: Sumac::Message::Object::Exposed
- Inherits:
-
Base
show all
- Defined in:
- lib/sumac/message/object/exposed.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
#initialize(connection) ⇒ Exposed
Returns a new instance of Exposed.
6
7
8
9
10
|
# File 'lib/sumac/message/object/exposed.rb', line 6
def initialize(connection)
super
@orgin = nil
@id = nil
end
|
Instance Method Details
#invert_orgin ⇒ Object
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/sumac/message/object/exposed.rb', line 59
def invert_orgin
raise MessageError unless setup?
case @orgin
when 'local'
@orgin = 'remote'
when 'remote'
@orgin = 'local'
end
nil
end
|
#parse_json_structure(json_structure) ⇒ Object
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/sumac/message/object/exposed.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'
raise MessageError unless json_structure['orgin'] == 'local' || json_structure['orgin'] == 'remote'
@orgin = json_structure['orgin']
raise MessageError unless json_structure['id'].is_a?(::Integer)
@id = json_structure['id']
nil
end
|
#parse_native_object(native_object) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/sumac/message/object/exposed.rb', line 23
def parse_native_object(native_object)
case
when native_object.respond_to?(:__sumac_exposed_object__)
@orgin = 'local'
@id = @connection.local_references.from_object(native_object).exposed_id
when native_object.is_a?(RemoteObject)
@orgin = 'remote'
@id = @connection.remote_references.from_object(native_object).exposed_id
else
raise MessageError
end
nil
end
|
#to_json_structure ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/sumac/message/object/exposed.rb', line 37
def to_json_structure
raise MessageError unless setup?
{
'message_type' => 'object',
'object_type' => 'exposed',
'orgin' => @orgin,
'id' => @id
}
end
|
#to_native_object ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/sumac/message/object/exposed.rb', line 47
def to_native_object
raise MessageError unless setup?
case @orgin
when 'local'
native_object = @connection.local_references.from_id(@id).exposed_object
raise MessageError unless native_object
native_object
when 'remote'
@connection.remote_references.from_id(@id).remote_object
end
end
|