Class: Sumac::Message::Object
- Inherits:
-
Sumac::Message
- Object
- Sumac::Message
- Sumac::Message::Object
- Defined in:
- lib/sumac/message/object.rb,
lib/sumac/message/object/base.rb,
lib/sumac/message/object/null.rb,
lib/sumac/message/object/array.rb,
lib/sumac/message/object/float.rb,
lib/sumac/message/object/string.rb,
lib/sumac/message/object/boolean.rb,
lib/sumac/message/object/exposed.rb,
lib/sumac/message/object/integer.rb,
lib/sumac/message/object/exception.rb,
lib/sumac/message/object/hash_table.rb,
lib/sumac/message/object/exposed_child.rb,
lib/sumac/message/object/native_exception.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Array, Base, Boolean, Exception, Exposed, ExposedChild, Float, HashTable, Integer, NativeException, Null, String
Class Method Summary collapse
- .from_json_structure(connection, json_structure) ⇒ Object
- .from_native_object(connection, native_object) ⇒ Object
Methods inherited from Sumac::Message
from_json, #initialize, #to_json
Constructor Details
This class inherits a constructor from Sumac::Message
Class Method Details
.from_json_structure(connection, json_structure) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sumac/message/object.rb', line 5 def self.from_json_structure(connection, json_structure) raise MessageError unless json_structure.is_a?(::Hash) && json_structure['message_type'] == 'object' object_class = case json_structure['object_type'] when 'null' Null when 'boolean' Boolean when 'exception' Exception when 'native_exception' NativeException when 'integer' Integer when 'float' Float when 'string' String when 'array' Array when 'hash_table' HashTable when 'exposed' Exposed when 'exposed_child' ExposedChild else raise MessageError end object = object_class.from_json_structure(connection, json_structure) object end |
.from_native_object(connection, native_object) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/sumac/message/object.rb', line 38 def self.from_native_object(connection, native_object) object_class = case when native_object.is_a?(RemoteObject) || (native_object.respond_to?(:__sumac_exposed_object__) && native_object.respond_to?(:__native_id__)) Exposed when native_object.is_a?(RemoteObjectChild) || (native_object.respond_to?(:__sumac_exposed_object__) && native_object.respond_to?(:__parent__)) ExposedChild when native_object == nil Null when native_object == true || native_object == false Boolean when Exception.map.transpose[1].any? { |klass| native_object.is_a?(klass) } Exception when native_object.is_a?(::Exception) NativeException when native_object.is_a?(::Integer) Integer when native_object.is_a?(::Float) Float when native_object.is_a?(::String) String when native_object.is_a?(::Array) Array when native_object.is_a?(::Hash) HashTable else raise UnexposableObjectError end object = object_class.from_native_object(connection, native_object) object end |