firm 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/firm/serializer/json.rb +11 -16
- data/lib/firm/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c1c7b999e2db422d608d8aaf8e28a9bace6824640f50a8e5dabb30e2ca89a36
|
4
|
+
data.tar.gz: a16d62247a09cc2e1d8b3c4d2a990ffefb7b48c18f6f1d8f27e12c770ff103eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c45a0bc530a143ad8b37de7e00f6fdd4a2af91ffb52b18ce86f91ffac390ea05825d58b042e29361a96fd762be58d210d141bdb88d9748c3232e7c30232b8cc
|
7
|
+
data.tar.gz: 939fe265f4f55f1255851e5f246b73ca416c6649af2ffcdad6aa8fb63341289ef64c71678bc02a7372c66acd6a91a26111ebc049d2a571b5f3f189f7010d3fb2
|
data/lib/firm/serializer/json.rb
CHANGED
@@ -148,20 +148,20 @@ module FIRM
|
|
148
148
|
def json_create(object)
|
149
149
|
data = object['data']
|
150
150
|
# deserializing (anchor) object or alias
|
151
|
-
if
|
152
|
-
if Serializable::Aliasing.restored?(self,
|
151
|
+
if object.has_key?('*id')
|
152
|
+
if Serializable::Aliasing.restored?(self, object['*id'])
|
153
153
|
# resolving an already restored anchor for this alias
|
154
|
-
Serializable::Aliasing.resolve_anchor(self,
|
154
|
+
Serializable::Aliasing.resolve_anchor(self, object['*id'])
|
155
155
|
else
|
156
156
|
# in case of cyclic references JSON will restore aliases before the anchors
|
157
157
|
# so in this case we allocate an instance here and register it as
|
158
158
|
# the anchor; when the anchor is restored it will re-use this instance to initialize & restore
|
159
159
|
# the properties
|
160
|
-
Serializable::Aliasing.restore_anchor(
|
160
|
+
Serializable::Aliasing.restore_anchor(object['*id'], self.allocate)
|
161
161
|
end
|
162
162
|
else
|
163
|
-
instance = if
|
164
|
-
anchor_id =
|
163
|
+
instance = if object.has_key?('&id')
|
164
|
+
anchor_id = object['&id'] # extract anchor id
|
165
165
|
if Serializable::Aliasing.restored?(self, anchor_id)
|
166
166
|
# in case of cyclic references an alias will already have restored the anchor instance
|
167
167
|
# (default constructed); retrieve that instance here for deserialization of properties
|
@@ -192,19 +192,14 @@ module FIRM
|
|
192
192
|
anchor_data = Serializable::Aliasing.get_anchor_data(self)
|
193
193
|
# retroactively insert the anchor in the anchored instance's serialization data
|
194
194
|
anchor_data['&id'] = anchor unless anchor_data.has_key?('&id')
|
195
|
-
json_data[
|
196
|
-
'*id' => anchor
|
197
|
-
}
|
195
|
+
json_data['*id'] = anchor
|
198
196
|
else
|
199
197
|
# register anchor object **before** serializing properties to properly handle cycling (bidirectional
|
200
198
|
# references)
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
json_data['data'] =
|
205
|
-
json_data['data'].merge!(json_data['data'].transform_values { |v| v.respond_to?(:as_json) ? v.as_json : v })
|
206
|
-
else
|
207
|
-
json_data['data'] = for_serialize(Serializable::Aliasing.register_anchor_object(self, {}))
|
199
|
+
Serializable::Aliasing.register_anchor_object(self, json_data)
|
200
|
+
data = for_serialize({})
|
201
|
+
unless data.empty?
|
202
|
+
json_data['data'] = data
|
208
203
|
json_data['data'].transform_values! { |v| v.respond_to?(:as_json) ? v.as_json : v }
|
209
204
|
end
|
210
205
|
end
|
data/lib/firm/version.rb
CHANGED