oj 2.0.12 → 2.0.13

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of oj might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6d89419541ffeaab83eaea37802686aae4fab16
4
- data.tar.gz: 0d6fd040e9438dbee988ee0ef7b5f35ea31e3b7e
3
+ metadata.gz: 668ead8e90334db6467d560eea8f2bb1f514fc53
4
+ data.tar.gz: 2556e815c19eaf4b0a2cdd432a25942420166cfe
5
5
  SHA512:
6
- metadata.gz: 01a5f4dbfc93069e199591710d4bf98df329b48f58bb29eb5a54df896a5fa217a79685a63cedf2a88af86a32519083f32d608a93059104255fdffa7da6d58650
7
- data.tar.gz: d16b98eedefb8e483df1f8ea14c6ed4a8036943501864334f19b8bfc7221498059343313c7aa722f592fc210b4c8eb0ce0cfefd532ba7017c82a389856a319ed
6
+ metadata.gz: 63163bdb7c6b7b1580072f33c8256126cf087313cd3f85ba3cb899431ce139a81ee24eafbc11fa362e1611b02ecaadb6bf58bf2cc1d2a1c55aebbbd6341d0535
7
+ data.tar.gz: 3fee65bcd045885bed8e744ea4f51cb6bb93c14220c2de5ef272d624aa03aa1949f3afca1da02ad10102396052cb5a898020d338e9064916dccc94a140dc3231
data/README.md CHANGED
@@ -14,7 +14,7 @@ A fast JSON parser and Object marshaller as a Ruby gem.
14
14
 
15
15
  *RubyGems* *repo*: https://rubygems.org/gems/oj
16
16
 
17
- ## <a name="follow">Follow @oxgem on Twitter</a>
17
+ ## <a name="follow">Follow @peterohler on Twitter</a>
18
18
 
19
19
  [Follow @peterohler on Twitter](http://twitter.com/#!/peterohler) for announcements and news about the Oj gem.
20
20
 
@@ -32,23 +32,16 @@ A fast JSON parser and Object marshaller as a Ruby gem.
32
32
 
33
33
  ## <a name="release">Release Notes</a>
34
34
 
35
- ### Release 2.0.12
35
+ ### Release 2.0.13
36
36
 
37
- - Another fix for mimic.
37
+ - Mimic is better at masking out json gem but the oj_mimic_json gem does not
38
+ work with ruby 2.0.0 correctly. The Oj.mimic_JSON() method should be called
39
+ directly either before or after the json gem is required. Depending on the
40
+ situation one may work better than the other. Oj.mimic_JSON() may now be
41
+ called multiple times.
38
42
 
39
- - mimic_JSON now can now be called after loading the json gem. This will
40
- replace the json gem methods after loading. This may be more compatible in
41
- many cases.
42
-
43
- ### Release 2.0.11
44
-
45
- - Fixed mimic issue with Debian
46
-
47
- - Added option to not cache classes when loading. This should be used when classes are dynamically unloaded and the redefined.
48
-
49
- - Float rounding improved by limiting decimal places to 15 places.
50
-
51
- - Fixed xml time dumping test.
43
+ - Changed dump to put closing array brackets and closing object curlies on the
44
+ line following the last element if :indent is set to greater than zero.
52
45
 
53
46
  ## <a name="description">Description</a>
54
47
 
@@ -362,23 +355,25 @@ without Objects or numbers (for JSON Pure, Yajl, and Messagepack) JSON:
362
355
 
363
356
  ### Simple JSON Writing and Parsing:
364
357
 
365
- require 'oj'
366
-
367
- h = { 'one' => 1, 'array' => [ true, false ] }
368
- json = Oj.dump(h)
358
+ ```ruby
359
+ require 'oj'
369
360
 
370
- # json =
371
- # {
372
- # "one":1,
373
- # "array":[
374
- # true,
375
- # false
376
- # ]
377
- # }
378
-
379
- h2 = Oj.load(json)
380
- puts "Same? #{h == h2}"
381
- # true
361
+ h = { 'one' => 1, 'array' => [ true, false ] }
362
+ json = Oj.dump(h)
363
+
364
+ # json =
365
+ # {
366
+ # "one":1,
367
+ # "array":[
368
+ # true,
369
+ # false
370
+ # ]
371
+ # }
372
+
373
+ h2 = Oj.load(json)
374
+ puts "Same? #{h == h2}"
375
+ # true
376
+ ```
382
377
 
383
378
  ### Object JSON format:
384
379
 
@@ -149,7 +149,7 @@ ascii_friendly_size(const uint8_t *str, size_t len) {
149
149
 
150
150
  inline static void
151
151
  fill_indent(Out out, int cnt) {
152
- if (0 < cnt && 0 < out->indent) {
152
+ if (0 < out->indent) {
153
153
  cnt *= out->indent;
154
154
  *out->cur++ = '\n';
155
155
  for (; 0 < cnt; cnt--) {
@@ -901,6 +901,7 @@ dump_hash(VALUE obj, int depth, int mode, Out out) {
901
901
  }
902
902
  if (0 < out->opts->dump_opts->indent_size) {
903
903
  int i;
904
+
904
905
  for (i = depth; 0 < i; i--) {
905
906
  strcpy(out->cur, out->opts->dump_opts->indent);
906
907
  out->cur += out->opts->dump_opts->indent_size;
@@ -1425,6 +1426,7 @@ dump_obj_attrs(VALUE obj, VALUE clas, slot_t id, int depth, Out out) {
1425
1426
  #endif
1426
1427
  out->depth = depth;
1427
1428
  }
1429
+ fill_indent(out, depth);
1428
1430
  *out->cur++ = '}';
1429
1431
  *out->cur = '\0';
1430
1432
  }
@@ -83,9 +83,9 @@ static char* read_quoted_value(ParseInfo pi);
83
83
  static void skip_comment(ParseInfo pi);
84
84
 
85
85
 
86
- /* This XML parser is a single pass, destructive, callback parser. It is a
86
+ /* This JSON parser is a single pass, destructive, callback parser. It is a
87
87
  * single pass parse since it only make one pass over the characters in the
88
- * XML document string. It is destructive because it re-uses the content of
88
+ * JSON document string. It is destructive because it re-uses the content of
89
89
  * the string for values in the callback and places \0 characters at various
90
90
  * places to mark the end of tokens and strings. It is a callback parser like
91
91
  * a SAX parser because it uses callback when document elements are
@@ -968,83 +968,84 @@ mimic_create_id(VALUE self, VALUE id) {
968
968
  /* Document-method: mimic_JSON
969
969
  * call-seq: mimic_JSON() => Module
970
970
  *
971
- * Creates the JSON module with methods and classes to mimic the JSON
972
- * gem. After this method is invoked calls that expect the JSON module will
973
- * use Oj instead and be faster than the original JSON. Most options that
974
- * could be passed to the JSON methods are supported. The calls to set parser
975
- * or generator will not raise an Exception but will not have any effect.
971
+ * Creates the JSON module with methods and classes to mimic the JSON gem. After
972
+ * this method is invoked calls that expect the JSON module will use Oj instead
973
+ * and be faster than the original JSON. Most options that could be passed to
974
+ * the JSON methods are supported. The calls to set parser or generator will not
975
+ * raise an Exception but will not have any effect. The method can also be
976
+ * called after the json gem is loaded. The necessary methods on the json gem
977
+ * will be replaced with Oj methods.
976
978
  */
977
979
  static VALUE
978
980
  define_mimic_json(int argc, VALUE *argv, VALUE self) {
979
- if (Qnil == mimic) {
980
- VALUE ext;
981
- VALUE dummy;
981
+ VALUE ext;
982
+ VALUE dummy;
982
983
 
983
- // Either set the paths to indicate JSON has been loaded or replaces the
984
- // methods if it has been loaded.
985
- if (rb_const_defined_at(rb_cObject, rb_intern("JSON"))) {
986
- mimic = rb_const_get_at(rb_cObject, rb_intern("JSON"));
987
- } else {
988
- mimic = rb_define_module("JSON");
989
- }
990
- if (rb_const_defined_at(mimic, rb_intern("Ext"))) {
991
- ext = rb_const_get_at(mimic, rb_intern("Ext"));
984
+ // Either set the paths to indicate JSON has been loaded or replaces the
985
+ // methods if it has been loaded.
986
+ if (rb_const_defined_at(rb_cObject, rb_intern("JSON"))) {
987
+ mimic = rb_const_get_at(rb_cObject, rb_intern("JSON"));
988
+ } else {
989
+ mimic = rb_define_module("JSON");
990
+ }
991
+ if (rb_const_defined_at(mimic, rb_intern("Ext"))) {
992
+ ext = rb_const_get_at(mimic, rb_intern("Ext"));
993
+ } else {
994
+ ext = rb_define_module_under(mimic, "Ext");
995
+ }
996
+ if (!rb_const_defined_at(ext, rb_intern("Parser"))) {
997
+ dummy = rb_define_class_under(ext, "Parser", rb_cObject);
998
+ }
999
+ if (!rb_const_defined_at(ext, rb_intern("Generator"))) {
1000
+ dummy = rb_define_class_under(ext, "Generator", rb_cObject);
1001
+ }
1002
+ // convince Ruby that the json gem has already been loaded
1003
+ dummy = rb_gv_get("$LOADED_FEATURES");
1004
+ if (rb_type(dummy) == T_ARRAY) {
1005
+ rb_ary_push(dummy, rb_str_new2("json"));
1006
+ if (0 < argc) {
1007
+ VALUE mimic_args[1];
1008
+
1009
+ *mimic_args = *argv;
1010
+ rb_funcall2(Oj, rb_intern("mimic_loaded"), 1, mimic_args);
992
1011
  } else {
993
- ext = rb_define_module_under(mimic, "Ext");
1012
+ rb_funcall2(Oj, rb_intern("mimic_loaded"), 0, 0);
994
1013
  }
995
- if (!rb_const_defined_at(ext, rb_intern("Parser"))) {
996
- dummy = rb_define_class_under(ext, "Parser", rb_cObject);
997
- }
998
- if (!rb_const_defined_at(ext, rb_intern("Generator"))) {
999
- dummy = rb_define_class_under(ext, "Generator", rb_cObject);
1000
- }
1001
- // convince Ruby that the json gem has already been loaded
1002
- dummy = rb_gv_get("$LOADED_FEATURES");
1003
- if (rb_type(dummy) == T_ARRAY) {
1004
- rb_ary_push(dummy, rb_str_new2("json"));
1005
- if (0 < argc) {
1006
- VALUE mimic_args[1];
1007
-
1008
- *mimic_args = *argv;
1009
- rb_funcall2(Oj, rb_intern("mimic_loaded"), 1, mimic_args);
1010
- } else {
1011
- rb_funcall2(Oj, rb_intern("mimic_loaded"), 0, 0);
1012
- }
1013
- }
1014
- dummy = rb_gv_get("$VERBOSE");
1015
- rb_gv_set("$VERBOSE", Qfalse);
1016
- rb_define_module_function(mimic, "parser=", no_op1, 1);
1017
- rb_define_module_function(mimic, "generator=", no_op1, 1);
1018
- rb_define_module_function(mimic, "create_id=", mimic_create_id, 1);
1019
-
1020
- rb_define_module_function(mimic, "dump", mimic_dump, -1);
1021
- rb_define_module_function(mimic, "load", mimic_load, -1);
1022
- rb_define_module_function(mimic, "restore", mimic_load, -1);
1023
- rb_define_module_function(mimic, "recurse_proc", mimic_recurse_proc, 1);
1024
- rb_define_module_function(mimic, "[]", mimic_dump_load, -1);
1025
-
1026
- rb_define_module_function(mimic, "generate", mimic_generate, -1);
1027
- rb_define_module_function(mimic, "fast_generate", mimic_generate, -1);
1028
- rb_define_module_function(mimic, "pretty_generate", mimic_pretty_generate, -1);
1029
- /* for older versions of JSON, the deprecated unparse methods */
1030
- rb_define_module_function(mimic, "unparse", mimic_generate, -1);
1031
- rb_define_module_function(mimic, "fast_unparse", mimic_generate, -1);
1032
- rb_define_module_function(mimic, "pretty_unparse", mimic_pretty_generate, -1);
1033
-
1034
- rb_define_module_function(mimic, "parse", mimic_parse, -1);
1035
- rb_define_module_function(mimic, "parse!", mimic_parse, -1);
1036
- rb_gv_set("$VERBOSE", dummy);
1037
-
1038
- array_nl_sym = ID2SYM(rb_intern("array_nl")); rb_gc_register_address(&array_nl_sym);
1039
- create_additions_sym = ID2SYM(rb_intern("create_additions")); rb_gc_register_address(&create_additions_sym);
1040
- object_nl_sym = ID2SYM(rb_intern("object_nl")); rb_gc_register_address(&object_nl_sym);
1041
- space_before_sym = ID2SYM(rb_intern("space_before")); rb_gc_register_address(&space_before_sym);
1042
- space_sym = ID2SYM(rb_intern("space")); rb_gc_register_address(&space_sym);
1043
- symbolize_names_sym = ID2SYM(rb_intern("symbolize_names")); rb_gc_register_address(&symbolize_names_sym);
1044
-
1045
- oj_default_options.mode = CompatMode;
1046
- oj_default_options.ascii_only = Yes;
1047
1014
  }
1015
+ dummy = rb_gv_get("$VERBOSE");
1016
+ rb_gv_set("$VERBOSE", Qfalse);
1017
+ rb_define_module_function(mimic, "parser=", no_op1, 1);
1018
+ rb_define_module_function(mimic, "generator=", no_op1, 1);
1019
+ rb_define_module_function(mimic, "create_id=", mimic_create_id, 1);
1020
+
1021
+ rb_define_module_function(mimic, "dump", mimic_dump, -1);
1022
+ rb_define_module_function(mimic, "load", mimic_load, -1);
1023
+ rb_define_module_function(mimic, "restore", mimic_load, -1);
1024
+ rb_define_module_function(mimic, "recurse_proc", mimic_recurse_proc, 1);
1025
+ rb_define_module_function(mimic, "[]", mimic_dump_load, -1);
1026
+
1027
+ rb_define_module_function(mimic, "generate", mimic_generate, -1);
1028
+ rb_define_module_function(mimic, "fast_generate", mimic_generate, -1);
1029
+ rb_define_module_function(mimic, "pretty_generate", mimic_pretty_generate, -1);
1030
+ /* for older versions of JSON, the deprecated unparse methods */
1031
+ rb_define_module_function(mimic, "unparse", mimic_generate, -1);
1032
+ rb_define_module_function(mimic, "fast_unparse", mimic_generate, -1);
1033
+ rb_define_module_function(mimic, "pretty_unparse", mimic_pretty_generate, -1);
1034
+
1035
+ rb_define_module_function(mimic, "parse", mimic_parse, -1);
1036
+ rb_define_module_function(mimic, "parse!", mimic_parse, -1);
1037
+ rb_gv_set("$VERBOSE", dummy);
1038
+
1039
+ array_nl_sym = ID2SYM(rb_intern("array_nl")); rb_gc_register_address(&array_nl_sym);
1040
+ create_additions_sym = ID2SYM(rb_intern("create_additions")); rb_gc_register_address(&create_additions_sym);
1041
+ object_nl_sym = ID2SYM(rb_intern("object_nl")); rb_gc_register_address(&object_nl_sym);
1042
+ space_before_sym = ID2SYM(rb_intern("space_before")); rb_gc_register_address(&space_before_sym);
1043
+ space_sym = ID2SYM(rb_intern("space")); rb_gc_register_address(&space_sym);
1044
+ symbolize_names_sym = ID2SYM(rb_intern("symbolize_names")); rb_gc_register_address(&symbolize_names_sym);
1045
+
1046
+ oj_default_options.mode = CompatMode;
1047
+ oj_default_options.ascii_only = Yes;
1048
+
1048
1049
  return mimic;
1049
1050
  }
1050
1051
 
@@ -2,19 +2,15 @@
2
2
  module Oj
3
3
 
4
4
  def self.mimic_loaded(mimic_paths=[])
5
- gems_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__))))
6
- Dir.foreach(gems_dir) do |gem|
7
- next unless (gem.start_with?('json') || gem.start_with?('json_pure'))
8
- $LOADED_FEATURES << File.join(gems_dir, gem, 'lib', 'json.rb')
9
- end
10
- # and another approach in case the first did not get all
11
5
  $LOAD_PATH.each do |d|
12
6
  next unless File.exist?(d)
13
- Dir.foreach(d) do |file|
14
- next unless file.end_with?('json.rb')
15
- $LOADED_FEATURES << File.join(d, file) unless $LOADED_FEATURES.include?(file)
7
+ offset = d.size() + 1
8
+ Dir.glob(File.join(d, '**', '*.rb')).each do |file|
9
+ next unless file[offset..-1].start_with?('json')
10
+ $LOADED_FEATURES << file unless $LOADED_FEATURES.include?(file)
16
11
  end
17
12
  end
18
13
  mimic_paths.each { |p| $LOADED_FEATURES << p }
14
+ $LOADED_FEATURES << 'json' unless $LOADED_FEATURES.include?('json')
19
15
  end
20
16
  end
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '2.0.12'
4
+ VERSION = '2.0.13'
5
5
  end
@@ -507,11 +507,13 @@ class Juice < ::Test::Unit::TestCase
507
507
  assert(%{{
508
508
  "^o":"Jeez",
509
509
  "x":true,
510
- "y":58}} == json ||
510
+ "y":58
511
+ }} == json ||
511
512
  %{{
512
513
  "^o":"Jeez",
513
514
  "y":58,
514
- "x":true}} == json)
515
+ "x":true
516
+ }} == json)
515
517
  obj2 = Oj.load(json, :mode => :object)
516
518
  assert_equal(obj, obj2)
517
519
  end
@@ -543,11 +545,13 @@ class Juice < ::Test::Unit::TestCase
543
545
  assert(%{{
544
546
  "^o":"Jazz",
545
547
  "x":true,
546
- "y":58}} == json ||
548
+ "y":58
549
+ }} == json ||
547
550
  %{{
548
551
  "^o":"Jazz",
549
552
  "y":58,
550
- "x":true}} == json)
553
+ "x":true
554
+ }} == json)
551
555
  obj2 = Oj.load(json, :mode => :object)
552
556
  assert_equal(obj, obj2)
553
557
  end
@@ -596,11 +600,13 @@ class Juice < ::Test::Unit::TestCase
596
600
  assert(%{{
597
601
  "^o":"Orange",
598
602
  "x":true,
599
- "y":58}} == json ||
603
+ "y":58
604
+ }} == json ||
600
605
  %{{
601
606
  "^o":"Orange",
602
607
  "y":58,
603
- "x":true}} == json)
608
+ "x":true
609
+ }} == json)
604
610
  obj2 = Oj.load(json, :mode => :object)
605
611
  assert_equal(obj, obj2)
606
612
  end
@@ -625,10 +631,12 @@ class Juice < ::Test::Unit::TestCase
625
631
  json = Oj.dump(obj, :mode => :compat, :indent => 2)
626
632
  assert(%{{
627
633
  "x":true,
628
- "y":58}} == json ||
634
+ "y":58
635
+ }} == json ||
629
636
  %{{
630
637
  "y":58,
631
- "x":true}} == json)
638
+ "x":true
639
+ }} == json)
632
640
  end
633
641
  def test_object_object
634
642
  obj = Jam.new(true, 58)
@@ -636,11 +644,13 @@ class Juice < ::Test::Unit::TestCase
636
644
  assert(%{{
637
645
  "^o":"Jam",
638
646
  "x":true,
639
- "y":58}} == json ||
647
+ "y":58
648
+ }} == json ||
640
649
  %{{
641
650
  "^o":"Jam",
642
651
  "y":58,
643
- "x":true}} == json)
652
+ "x":true
653
+ }} == json)
644
654
  obj2 = Oj.load(json, :mode => :object)
645
655
  assert_equal(obj, obj2)
646
656
  end
@@ -651,11 +661,13 @@ class Juice < ::Test::Unit::TestCase
651
661
  assert(%{{
652
662
  "^o":"Jam",
653
663
  "x":true,
654
- "y":58}} == json ||
664
+ "y":58
665
+ }} == json ||
655
666
  %{{
656
667
  "^o":"Jam",
657
668
  "y":58,
658
- "x":true}} == json)
669
+ "x":true
670
+ }} == json)
659
671
  obj2 = Oj.load(json, :mode => :object, :class_cache => false)
660
672
  assert_equal(obj, obj2)
661
673
  end
@@ -869,12 +881,14 @@ class Juice < ::Test::Unit::TestCase
869
881
  "^o":"Jam",
870
882
  "^i":1,
871
883
  "x":"^r1",
872
- "y":58}} == json ||
884
+ "y":58
885
+ }} == json ||
873
886
  %{{
874
887
  "^o":"Jam",
875
888
  "^i":1,
876
889
  "y":58,
877
- "x":"^r1"}} == json)
890
+ "x":"^r1"
891
+ }} == json)
878
892
  obj2 = Oj.load(json, :mode => :object, :circular => true)
879
893
  assert_equal(obj2.x.__id__, obj2.__id__)
880
894
  end
@@ -896,7 +910,8 @@ class Juice < ::Test::Unit::TestCase
896
910
  assert_equal(%{[
897
911
  "^i1",
898
912
  7,
899
- "^r1"]}, json)
913
+ "^r1"
914
+ ]}, json)
900
915
  a2 = Oj.load(json, :mode => :object, :circular => true)
901
916
  assert_equal(a2[1].__id__, a2.__id__)
902
917
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oj
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.12
4
+ version: 2.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-28 00:00:00.000000000 Z
11
+ date: 2013-05-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'The fastest JSON parser and object serializer. '
14
14
  email: peter@ohler.com