Class: FIRM::Serializable::ID
- Inherits:
-
Object
- Object
- FIRM::Serializable::ID
- Extended by:
- JSON::SerializeClassMethods, XML::SerializeClassMethods
- Defined in:
- lib/firm/serializable.rb,
lib/firm/serialize/id.rb,
lib/firm/serializer/xml.rb,
lib/firm/serializer/json.rb,
lib/firm/serializer/yaml.rb
Overview
Serializable unique ids. This class makes sure to maintain uniqueness across serialization/deserialization cycles and keeps all shared instances within a single (serialized/deserialized) object set in sync.
Constant Summary
Constants included from FIRM::Serializable
Class Method Summary collapse
-
.deserialize(source, format: Serializable.default_format) ⇒ Object
Deserializes object from source data.
Instance Method Summary collapse
- #encode_with(coder) ⇒ Object
-
#finalize_from_serialized ⇒ self
protected
Noop for ID instances.
-
#for_serialize(hash, _excludes = nil) ⇒ Object
protected
Noop for ID instances.
-
#from_serialized(_hash) ⇒ self
protected
Noop for ID instances.
-
#init_from_serialized(_data) ⇒ Object
protected
Initializes a newly allocated instance for subsequent deserialization (optionally initializing using the given data hash).
- #init_with(_coder) ⇒ Object
- #inspect ⇒ Object
-
#serialize(io = nil, pretty: false, format: Serializable.default_format) ⇒ Object
Serialize this object.
-
#serialize_disabled? ⇒ Boolean
Always returns false for IDs.
- #to_i ⇒ Object
- #to_s ⇒ Object
Methods included from JSON::SerializeClassMethods
Methods included from XML::SerializeClassMethods
Methods included from JSON::SerializeInstanceMethods
Methods included from XML::SerializeInstanceMethods
Methods included from FIRM::Serializable
[], default_format, default_format=, formatters, included, register, serializables, serialize, tls_vars
Class Method Details
.deserialize(source, format: Serializable.default_format) ⇒ Object
Deserializes object from source data
19 20 21 |
# File 'lib/firm/serialize/id.rb', line 19 def deserialize(source, format: Serializable.default_format) Serializable.deserialize(source, format: format) end |
Instance Method Details
#encode_with(coder) ⇒ Object
127 128 129 |
# File 'lib/firm/serializer/yaml.rb', line 127 def encode_with(coder) for_serialize(coder) end |
#finalize_from_serialized ⇒ self (protected)
Noop for ID instances.
75 76 77 78 |
# File 'lib/firm/serialize/id.rb', line 75 def finalize_from_serialized # no finalization necessary self end |
#for_serialize(hash, _excludes = nil) ⇒ Object (protected)
Noop for ID instances.
57 58 59 |
# File 'lib/firm/serialize/id.rb', line 57 def for_serialize(hash, _excludes = nil) hash end |
#from_serialized(_hash) ⇒ self (protected)
Noop for ID instances.
66 67 68 69 |
# File 'lib/firm/serialize/id.rb', line 66 def from_serialized(_hash) # no deserializing necessary self end |
#init_from_serialized(_data) ⇒ Object (protected)
Initializes a newly allocated instance for subsequent deserialization (optionally initializing using the given data hash). The default implementation calls the standard #initialize method without arguments (default constructor) and leaves the property restoration to a subsequent call to the instance method #from_serialized(data). Classes that do not support a default constructor can override this class method and implement a custom initialization scheme.
47 48 49 50 |
# File 'lib/firm/serialize/id.rb', line 47 def init_from_serialized(_data) initialize self end |
#init_with(_coder) ⇒ Object
131 132 133 |
# File 'lib/firm/serializer/yaml.rb', line 131 def init_with(_coder) # noop end |
#inspect ⇒ Object
92 93 94 |
# File 'lib/firm/serialize/id.rb', line 92 def inspect to_s end |
#serialize(pretty: false, format: Serializable.default_format) ⇒ String #serialize(io, pretty: false, format: Serializable.default_format) ⇒ IO
Serialize this object
35 36 37 |
# File 'lib/firm/serialize/id.rb', line 35 def serialize(io = nil, pretty: false, format: Serializable.default_format) Serializable[format].dump(self, io, pretty: pretty) end |
#serialize_disabled? ⇒ Boolean
Always returns false for IDs.
84 85 86 |
# File 'lib/firm/serialize/id.rb', line 84 def serialize_disabled? false end |
#to_i ⇒ Object
96 97 98 |
# File 'lib/firm/serialize/id.rb', line 96 def to_i object_id end |
#to_s ⇒ Object
88 89 90 |
# File 'lib/firm/serialize/id.rb', line 88 def to_s "FIRM::Serializable::ID<#{object_id}>" end |