firm 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 823d2ee34c56ec4457626d9dd06586825f33a01ad3dd34dfd135f9cdefafdd66
4
- data.tar.gz: f0c33ff04609cfa111f98886ca3d92cab1478d81b5bde280c2000bdcaca614c5
3
+ metadata.gz: 2f6498bd122a2588336365f1120c424cfdf65fd5e05d87b4c5b3175c92d72965
4
+ data.tar.gz: bbf7816402e9f0c1b977dd47cfefc6b600e389c6e3710436a8d62fc9eee42a3d
5
5
  SHA512:
6
- metadata.gz: 9a7c5b5446f5bc1aae9e6f2fcaa3baa0d3589b235144367443292e2785570ce5765f3612fc10c9fc010e7ce4f0e820239167a5e6f4ef5ad77fe2ecdbc0820349
7
- data.tar.gz: 129cb0defe0a5628f9c7731e23ba73b90747f973cfc2931021612f4d271efbd39b80bbb60c8ca751f64fa549110fd79362ca751dfa78d11e68e9c127856da5de
6
+ metadata.gz: 0fcc10bf8e5d448f02482fe453fc20433ca26781d08c55a0dba0e0b0947e17aae91d4f97d45c858ae5f73b170c37cb0c646caad3904d573745b8737ac6e61aac
7
+ data.tar.gz: 7bc179e75ea98e4505156d3ff59d53f7d07931c0d24b40e4adb127ae82be1bcf205a19b0811bebd557f4c519dd507f8802c8e7f25c0ed60ef9d6c75f2fee30ef
data/README.md CHANGED
@@ -8,7 +8,8 @@
8
8
 
9
9
  ## Introduction
10
10
 
11
- FIRM is a pure Ruby library providing output format independent object (de-)serialization support.
11
+ FIRM is a pure Ruby library that works across different Ruby implementations like MRI Ruby and JRuby providing output
12
+ format independent object (de-)serialization support.
12
13
 
13
14
  FIRM is explicitly **NOT** intended as a non-discriminative marshaling library (dumping any object's attributes)
14
15
  but rather as structured and safe serialization library requiring users to think about what state they want
@@ -198,8 +198,15 @@ module FIRM
198
198
  else
199
199
  # register anchor object **before** serializing properties to properly handle cycling (bidirectional
200
200
  # references)
201
- json_data['data'] = for_serialize(Serializable::Aliasing.register_anchor_object(self, {}))
202
- json_data['data'].transform_values! { |v| v.respond_to?(:as_json) ? v.as_json : v }
201
+ if defined? JRUBY_VERSION
202
+ # JRuby has a problem modifying a hash while iterating it so we create a new copy here which we
203
+ # merge with the original because that may be updated with an anchor id
204
+ json_data['data'] = for_serialize(Serializable::Aliasing.register_anchor_object(self, {}))
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, {}))
208
+ json_data['data'].transform_values! { |v| v.respond_to?(:as_json) ? v.as_json : v }
209
+ end
203
210
  end
204
211
  json_data
205
212
  end
@@ -182,7 +182,11 @@ module FIRM
182
182
  xml
183
183
  end
184
184
  def from_xml(xml)
185
- xml.content
185
+ # in case the xml was somehow formatted it may be additional text nodes
186
+ # get inserted because of added space and/or newlines
187
+ # (like with JRuby's Nokogiri when outputting pretty formatted XML)
188
+ # so just in case look up the one CDATA child and only use that one's content
189
+ xml.children.find { |child| child.cdata? }&.text || ''
186
190
  end
187
191
  end
188
192
 
@@ -212,8 +216,9 @@ module FIRM
212
216
  xml
213
217
  end
214
218
  def from_xml(xml)
215
- case (s = xml.content)
216
- when 'NaN' then :Float::NAN
219
+ s = xml.children.find { |child| child.cdata? }&.text
220
+ case s
221
+ when nil, 'NaN' then :Float::NAN
217
222
  when 'Infinity' then ::Float::INFINITY
218
223
  when '-Infinity' then -::Float::INFINITY
219
224
  else
@@ -307,7 +312,12 @@ module FIRM
307
312
  xml
308
313
  end
309
314
  def from_xml(xml)
310
- ::BigDecimal._load(xml.content)
315
+ # in case the xml was somehow formatted it may be additional text nodes
316
+ # get inserted because of added space and/or newlines
317
+ # (like with JRuby's Nokogiri when outputting pretty formatted XML)
318
+ # so just in case look up the one CDATA child and only use that one's content
319
+ data = xml.children.find { |child| child.cdata? }&.text
320
+ ::BigDecimal._load(data || '')
311
321
  end
312
322
  end
313
323
  end
data/lib/firm/version.rb CHANGED
@@ -4,6 +4,6 @@
4
4
  module FIRM
5
5
 
6
6
  # FIRM version
7
- VERSION = "0.9.1"
7
+ VERSION = "0.9.2"
8
8
 
9
9
  end
@@ -228,7 +228,7 @@ module SerializerTestMixin
228
228
  assert_equal(obj, obj_new)
229
229
 
230
230
  Struct.new('MyStruct', :one, :two) unless defined? Struct::MyStruct
231
- obj = Struct::MyStruct.new(one: Point.new(10, 90), two: Point.new(20, 80))
231
+ obj = Struct::MyStruct.new(Point.new(10, 90), Point.new(20, 80))
232
232
  obj_serial = obj.serialize
233
233
  assert_nothing_raised { obj_new = FIRM.deserialize(obj_serial) }
234
234
  assert_equal(obj, obj_new)
@@ -705,10 +705,12 @@ module SerializerTestMixin
705
705
  end
706
706
  end
707
707
 
708
+ require 'base64'
709
+
708
710
  class NestedSerializer
709
711
  include FIRM::Serializable
710
712
 
711
- property :nested, handler: :marshall_nested
713
+ property nested: :marshall_nested
712
714
 
713
715
  def initialize(serializable=nil)
714
716
  @nested = serializable
@@ -718,11 +720,13 @@ module SerializerTestMixin
718
720
 
719
721
  protected
720
722
 
721
- def marshall_nested(_id, *val)
723
+ def marshall_nested(*val)
722
724
  if val.empty?
723
- @nested.serialize
725
+ # as this results in another XML string to embed it is probably best to encode
726
+ # it (at least JRuby's Nokogiri version seems to have problems with this without encoding)
727
+ Base64.urlsafe_encode64(@nested.serialize)
724
728
  else
725
- @nested = FIRM.deserialize(val.first)
729
+ @nested = FIRM.deserialize(Base64.urlsafe_decode64(val.first))
726
730
  nil
727
731
  end
728
732
  end
@@ -746,9 +750,8 @@ module SerializerTestMixin
746
750
  ref_obj = RefUser.new(container.map[:seven].id, container.map[:eight].id, container.map[:nine].id)
747
751
  container.map[:ten] = ref_obj
748
752
  nest_obj = NestedSerializer.new(container)
749
- obj_serial = [nest_obj, container.map[:one], container.map[:two], container.map[:five], [container.map[:three], container.map[:four], container.map[:six]], ref_obj].serialize(nil, pretty: true)
750
- obj_new = nil
751
- assert_nothing_raised { obj_new = FIRM.deserialize(obj_serial) }
753
+ obj_serial = [nest_obj, container.map[:one], container.map[:two], container.map[:five], [container.map[:three], container.map[:four], container.map[:six]], ref_obj].serialize(pretty: true)
754
+ obj_new = assert_nothing_raised { FIRM.deserialize(obj_serial) }
752
755
  assert_instance_of(::Array, obj_new)
753
756
  assert_instance_of(NestedSerializer, obj_new[0])
754
757
  container = obj_new[0].nested
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Corino