oj 3.0.11 → 3.1.0

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
  SHA1:
3
- metadata.gz: 4f9a694459b58b7e423bd685ea28a1fcfb582a3c
4
- data.tar.gz: 609715b5ff8e615f59dbdceabdc7ec691c4f8287
3
+ metadata.gz: 921337fe55a2f80cc6537cb652c5d54a98dd39d3
4
+ data.tar.gz: acdf0cc3bdaed92fd5ecb0a7239cfcf88873c59b
5
5
  SHA512:
6
- metadata.gz: ad438e894a9540489bbc29c75d39972db15389e41b83700467736b3b1fb7e329c11def32cabc6753b2e60ae1a548f5fd5c89074057c4b6c8816b014c9fb5bd5d
7
- data.tar.gz: b25cdb2139bea0f973b80c421c956f0ecece0c50b70f6b87707f52ac452d418672d8e865026020804cb5bc69434ed3e0214c3034df116bba540ef955aa07c0d7
6
+ metadata.gz: d51c9c25369ca4c5d9b7cd5670e1d4d87ce3458b9e8760d1d893c37f48f4775b145f9fad1b2aba78ba5a157981d7cda854e3c091dd9cf4256f1c9bb096699bd8
7
+ data.tar.gz: bdc8810b381c0a6f822432443ba201a2ed37aa30c8fe3f2e2ce00c446cae53a4cfdd90cb796e29cb2bcf60e34c62b607cdd90bf8bbc7b1ca773ba840caed5899
@@ -750,6 +750,54 @@ mimic_state(VALUE self) {
750
750
  return state_class;
751
751
  }
752
752
 
753
+ void
754
+ oj_mimic_json_methods(VALUE json) {
755
+ VALUE json_error;
756
+
757
+ rb_define_module_function(json, "create_id=", mimic_set_create_id, 1);
758
+ rb_define_module_function(json, "create_id", mimic_create_id, 0);
759
+
760
+ rb_define_module_function(json, "dump", mimic_dump, -1);
761
+ rb_define_module_function(json, "load", mimic_load, -1);
762
+ rb_define_module_function(json, "restore", mimic_load, -1);
763
+ rb_define_module_function(json, "recurse_proc", mimic_recurse_proc, 1);
764
+ rb_define_module_function(json, "[]", mimic_dump_load, -1);
765
+
766
+ rb_define_module_function(json, "generate", oj_mimic_generate, -1);
767
+ rb_define_module_function(json, "fast_generate", oj_mimic_generate, -1);
768
+ rb_define_module_function(json, "pretty_generate", oj_mimic_pretty_generate, -1);
769
+ // For older versions of JSON, the deprecated unparse methods.
770
+ rb_define_module_function(json, "unparse", oj_mimic_generate, -1);
771
+ rb_define_module_function(json, "fast_unparse", oj_mimic_generate, -1);
772
+ rb_define_module_function(json, "pretty_unparse", oj_mimic_pretty_generate, -1);
773
+
774
+ rb_define_module_function(json, "parse", oj_mimic_parse, -1);
775
+ rb_define_module_function(json, "parse!", mimic_parse_bang, -1);
776
+
777
+ rb_define_module_function(json, "state", mimic_state, 0);
778
+
779
+ if (rb_const_defined_at(json, rb_intern("JSONError"))) {
780
+ json_error = rb_const_get(json, rb_intern("JSONError"));
781
+ } else {
782
+ json_error = rb_define_class_under(json, "JSONError", rb_eStandardError);
783
+ }
784
+ if (rb_const_defined_at(json, rb_intern("ParserError"))) {
785
+ oj_json_parser_error_class = rb_const_get(json, rb_intern("ParserError"));
786
+ } else {
787
+ oj_json_parser_error_class = rb_define_class_under(json, "ParserError", json_error);
788
+ }
789
+ if (rb_const_defined_at(json, rb_intern("GeneratorError"))) {
790
+ oj_json_generator_error_class = rb_const_get(json, rb_intern("GeneratorError"));
791
+ } else {
792
+ oj_json_generator_error_class = rb_define_class_under(json, "GeneratorError", json_error);
793
+ }
794
+ if (rb_const_defined_at(json, rb_intern("NestingError"))) {
795
+ rb_const_get(json, rb_intern("NestingError"));
796
+ } else {
797
+ rb_define_class_under(json, "NestingError", json_error);
798
+ }
799
+ }
800
+
753
801
  /* Document-module: JSON
754
802
  *
755
803
  * A mimic of the json gem module.
@@ -759,7 +807,6 @@ oj_define_mimic_json(int argc, VALUE *argv, VALUE self) {
759
807
  VALUE ext;
760
808
  VALUE dummy;
761
809
  VALUE verbose;
762
- VALUE json_error;
763
810
  VALUE json;
764
811
  VALUE generator;
765
812
 
@@ -804,27 +851,7 @@ oj_define_mimic_json(int argc, VALUE *argv, VALUE self) {
804
851
  state_class = rb_const_get_at(generator, rb_intern("State"));
805
852
  // TBD create all modules in mimic_loaded
806
853
 
807
- rb_define_module_function(json, "create_id=", mimic_set_create_id, 1);
808
- rb_define_module_function(json, "create_id", mimic_create_id, 0);
809
-
810
- rb_define_module_function(json, "dump", mimic_dump, -1);
811
- rb_define_module_function(json, "load", mimic_load, -1);
812
- rb_define_module_function(json, "restore", mimic_load, -1);
813
- rb_define_module_function(json, "recurse_proc", mimic_recurse_proc, 1);
814
- rb_define_module_function(json, "[]", mimic_dump_load, -1);
815
-
816
- rb_define_module_function(json, "generate", oj_mimic_generate, -1);
817
- rb_define_module_function(json, "fast_generate", oj_mimic_generate, -1);
818
- rb_define_module_function(json, "pretty_generate", oj_mimic_pretty_generate, -1);
819
- // For older versions of JSON, the deprecated unparse methods.
820
- rb_define_module_function(json, "unparse", oj_mimic_generate, -1);
821
- rb_define_module_function(json, "fast_unparse", oj_mimic_generate, -1);
822
- rb_define_module_function(json, "pretty_unparse", oj_mimic_pretty_generate, -1);
823
-
824
- rb_define_module_function(json, "parse", oj_mimic_parse, -1);
825
- rb_define_module_function(json, "parse!", mimic_parse_bang, -1);
826
-
827
- rb_define_module_function(json, "state", mimic_state, 0);
854
+ oj_mimic_json_methods(json);
828
855
 
829
856
  rb_define_method(rb_cObject, "to_json", mimic_object_to_json, -1);
830
857
 
@@ -832,27 +859,6 @@ oj_define_mimic_json(int argc, VALUE *argv, VALUE self) {
832
859
 
833
860
  symbolize_names_sym = ID2SYM(rb_intern("symbolize_names")); rb_gc_register_address(&symbolize_names_sym);
834
861
 
835
- if (rb_const_defined_at(json, rb_intern("JSONError"))) {
836
- json_error = rb_const_get(json, rb_intern("JSONError"));
837
- } else {
838
- json_error = rb_define_class_under(json, "JSONError", rb_eStandardError);
839
- }
840
- if (rb_const_defined_at(json, rb_intern("ParserError"))) {
841
- oj_json_parser_error_class = rb_const_get(json, rb_intern("ParserError"));
842
- } else {
843
- oj_json_parser_error_class = rb_define_class_under(json, "ParserError", json_error);
844
- }
845
- if (rb_const_defined_at(json, rb_intern("GeneratorError"))) {
846
- oj_json_generator_error_class = rb_const_get(json, rb_intern("GeneratorError"));
847
- } else {
848
- oj_json_generator_error_class = rb_define_class_under(json, "GeneratorError", json_error);
849
- }
850
- if (rb_const_defined_at(json, rb_intern("NestingError"))) {
851
- rb_const_get(json, rb_intern("NestingError"));
852
- } else {
853
- rb_define_class_under(json, "NestingError", json_error);
854
- }
855
-
856
862
  oj_default_options = mimic_object_to_json_options;
857
863
  oj_default_options.to_json = Yes;
858
864
 
@@ -21,6 +21,8 @@ bool oj_rails_hash_opt = false;
21
21
  bool oj_rails_array_opt = false;
22
22
  bool oj_rails_float_opt = false;
23
23
 
24
+ extern void oj_mimic_json_methods(VALUE json);
25
+
24
26
  static void dump_rails_val(VALUE obj, int depth, Out out, bool as_ok);
25
27
 
26
28
  extern VALUE Oj;
@@ -537,6 +539,27 @@ rails_optimize(int argc, VALUE *argv, VALUE self) {
537
539
  return Qnil;
538
540
  }
539
541
 
542
+ /* Document-module: mimic_JSON
543
+ * call-seq: mimic_JSON()
544
+ *
545
+ * Sets the JSON method to use Oj similar to Oj.mimic_JSON except with the
546
+ * ActiveSupport monkey patches instead of the json gem monkey patches.
547
+ */
548
+ VALUE
549
+ rails_mimic_json(VALUE self) {
550
+ VALUE json;
551
+
552
+ if (rb_const_defined_at(rb_cObject, rb_intern("JSON"))) {
553
+ json = rb_const_get_at(rb_cObject, rb_intern("JSON"));
554
+ } else {
555
+ json = rb_define_module("JSON");
556
+ }
557
+ oj_mimic_json_methods(json);
558
+ // TBD
559
+
560
+ return Qnil;
561
+ }
562
+
540
563
  /* Document-method: deoptimize
541
564
  * call-seq: deoptimize(*classes)
542
565
  *
@@ -851,6 +874,7 @@ oj_optimize_rails(VALUE self) {
851
874
  rails_set_encoder(self);
852
875
  rails_set_decoder(self);
853
876
  rails_optimize(0, NULL, self);
877
+ rails_mimic_json(self);
854
878
 
855
879
  return Qnil;
856
880
  }
@@ -874,6 +898,7 @@ oj_mimic_rails_init() {
874
898
  rb_define_module_function(rails, "optimize", rails_optimize, -1);
875
899
  rb_define_module_function(rails, "deoptimize", rails_deoptimize, -1);
876
900
  rb_define_module_function(rails, "optimized?", rails_optimized, 1);
901
+ rb_define_module_function(rails, "mimic_JSON?", rails_mimic_json, 0);
877
902
 
878
903
  rb_define_module_function(rails, "set_encoder", rails_set_encoder, 0);
879
904
  rb_define_module_function(rails, "set_decoder", rails_set_decoder, 0);
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '3.0.11'
4
+ VERSION = '3.1.0'
5
5
  end
@@ -11,6 +11,7 @@ require 'oj'
11
11
  Oj::Rails.set_encoder()
12
12
  Oj::Rails.set_decoder()
13
13
  Oj::Rails.optimize()
14
+ Oj::Rails.mimic_JSON()
14
15
  ```
15
16
 
16
17
  or simply call
@@ -11,7 +11,8 @@ require 'oj'
11
11
  # Sets the ActiveSupport encoder to be Oj and also wraps the setting of
12
12
  # globals.
13
13
  Oj::Rails.set_encoder()
14
- Oj::Rails.optimize(Hash, Array, BigDecimal, Time, Range, Regexp, ActiveSupport::TimeWithZone)
14
+ #Oj::Rails.optimize(Hash, Array, BigDecimal, Time, Range, Regexp, ActiveSupport::TimeWithZone)
15
+ Oj::Rails.optimize()
15
16
 
16
17
  class TestJSONEncoding < ActiveSupport::TestCase
17
18
  include TimeZoneTestHelpers
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: 3.0.11
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-02 00:00:00.000000000 Z
11
+ date: 2017-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler