oj 3.3.10 → 3.4.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: 687f7d149d0cf1490c71c850e9b899211bf93dff
4
- data.tar.gz: e60c06c52ab2946307618cdc78a180ed2333f19b
3
+ metadata.gz: 9badf52195a57cbb014c118468e251a6410492be
4
+ data.tar.gz: 8cf51afa4ee58bbb314625d6b4e4c91c69c1f816
5
5
  SHA512:
6
- metadata.gz: '0287e158af4e2637f70aeaef9bd90fbdd92270ba8b94d58eb77f3371671ead837638440677a67f00880b1b0024098ea31530f843950c434154f72dfd844d8854'
7
- data.tar.gz: 279a77556142e021b88e6e2b1b75ae93a11aa373dad3098f994559004ecfa4089ebd3514cd412b08004896438d014fde5a2c9dc27f87ad3558627920146870df
6
+ metadata.gz: 3366cc54755af4f3d8abbded2afac3b1235a4fe25315964d6d1225c69e849611eecedb2e7d893e14b72514bcc0115b1a2cce94bc007f0e8460230798d1531276
7
+ data.tar.gz: 02d082acfd67708b44582a8fe69e10a5f639cc56ec57484c56c283be96ffc4d64b0a41b4c31bac2f707225388b2f5cd2551c9e6aba048c4c973e6c6461a462a8
@@ -244,6 +244,9 @@ static int
244
244
  hash_cb(VALUE key, VALUE value, Out out) {
245
245
  int depth = out->depth;
246
246
 
247
+ if (oj_dump_ignore(out->opts, value)) {
248
+ return ST_CONTINUE;
249
+ }
247
250
  if (out->omit_nil && Qnil == value) {
248
251
  return ST_CONTINUE;
249
252
  }
@@ -529,6 +532,9 @@ dump_attr_cb(ID key, VALUE value, Out out) {
529
532
  size_t size;
530
533
  const char *attr;
531
534
 
535
+ if (oj_dump_ignore(out->opts, value)) {
536
+ return ST_CONTINUE;
537
+ }
532
538
  if (out->omit_nil && Qnil == value) {
533
539
  return ST_CONTINUE;
534
540
  }
@@ -1143,3 +1143,18 @@ oj_dump_float_printf(char *buf, size_t blen, VALUE obj, double d, const char *fo
1143
1143
  }
1144
1144
  return cnt;
1145
1145
  }
1146
+
1147
+ bool
1148
+ oj_dump_ignore(Options opts, VALUE obj) {
1149
+ if (NULL != opts->ignore && (ObjectMode == opts->mode || CustomMode == opts->mode)) {
1150
+ VALUE *vp = opts->ignore;
1151
+ VALUE clas = rb_obj_class(obj);
1152
+
1153
+ for (; Qnil != *vp; vp++) {
1154
+ if (clas == *vp) {
1155
+ return true;
1156
+ }
1157
+ }
1158
+ }
1159
+ return false;
1160
+ }
@@ -50,6 +50,8 @@ extern VALUE oj_remove_to_json(int argc, VALUE *argv, VALUE self);
50
50
 
51
51
  extern int oj_dump_float_printf(char *buf, size_t blen, VALUE obj, double d, const char *format);
52
52
 
53
+ extern bool oj_dump_ignore(Options opts, VALUE obj);
54
+
53
55
  inline static void
54
56
  assure_size(Out out, size_t len) {
55
57
  if (out->end - out->cur <= (long)len) {
@@ -227,6 +227,9 @@ hash_cb(VALUE key, VALUE value, Out out) {
227
227
  int depth = out->depth;
228
228
  long size = depth * out->indent + 1;
229
229
 
230
+ if (oj_dump_ignore(out->opts, value)) {
231
+ return ST_CONTINUE;
232
+ }
230
233
  if (out->omit_nil && Qnil == value) {
231
234
  return ST_CONTINUE;
232
235
  }
@@ -349,6 +352,9 @@ dump_attr_cb(ID key, VALUE value, Out out) {
349
352
  size_t size = depth * out->indent + 1;
350
353
  const char *attr = rb_id2name(key);
351
354
 
355
+ if (oj_dump_ignore(out->opts, value)) {
356
+ return ST_CONTINUE;
357
+ }
352
358
  if (out->omit_nil && Qnil == value) {
353
359
  return ST_CONTINUE;
354
360
  }
@@ -607,6 +613,10 @@ dump_obj_attrs(VALUE obj, VALUE clas, slot_t id, int depth, Out out) {
607
613
  vid = rb_to_id(*np);
608
614
  attr = rb_id2name(vid);
609
615
  value = rb_ivar_get(obj, vid);
616
+
617
+ if (oj_dump_ignore(out->opts, value)) {
618
+ continue;
619
+ }
610
620
  if (out->omit_nil && Qnil == value) {
611
621
  continue;
612
622
  }
@@ -735,6 +745,9 @@ dump_struct(VALUE obj, int depth, Out out, bool as_ok) {
735
745
 
736
746
  for (i = 0; i < cnt; i++) {
737
747
  v = RSTRUCT_GET(obj, i);
748
+ if (oj_dump_ignore(out->opts, v)) {
749
+ v = Qnil;
750
+ }
738
751
  assure_size(out, size);
739
752
  fill_indent(out, d3);
740
753
  oj_dump_obj_val(v, d3, out);
@@ -750,6 +763,9 @@ dump_struct(VALUE obj, int depth, Out out, bool as_ok) {
750
763
  for (i = 0; i < slen; i++) {
751
764
  assure_size(out, size);
752
765
  fill_indent(out, d3);
766
+ if (oj_dump_ignore(out->opts, v)) {
767
+ v = Qnil;
768
+ }
753
769
  oj_dump_obj_val(rb_struct_aref(obj, INT2FIX(i)), d3, out, 0, 0, true);
754
770
  *out->cur++ = ',';
755
771
  }
@@ -118,6 +118,7 @@ static VALUE escape_mode_sym;
118
118
  static VALUE float_prec_sym;
119
119
  static VALUE float_sym;
120
120
  static VALUE huge_sym;
121
+ static VALUE ignore_sym;
121
122
  static VALUE json_sym;
122
123
  static VALUE match_string_sym;
123
124
  static VALUE mode_sym;
@@ -207,7 +208,8 @@ struct _Options oj_default_options = {
207
208
  NULL, // head
208
209
  NULL, // tail
209
210
  { '\0' }, // err
210
- }
211
+ },
212
+ NULL, // ignore
211
213
  };
212
214
 
213
215
  /* Document-method: default_options()
@@ -244,6 +246,7 @@ struct _Options oj_default_options = {
244
246
  * - *:hash_class* [_Class_|_nil_] Class to use instead of Hash on load, :object_class can also be used
245
247
  * - *:array_class* [_Class_|_nil_] Class to use instead of Array on load
246
248
  * - *:omit_nil* [_true_|_false_] if true Hash and Object attributes with nil values are omitted
249
+ * - *:ignore* [_nil_|Array] either nil or an Array of classes to ignore when dumping
247
250
  *
248
251
  * Return [_Hash_] all current option settings.
249
252
  */
@@ -320,7 +323,18 @@ get_def_opts(VALUE self) {
320
323
  rb_hash_aset(opts, omit_nil_sym, oj_default_options.dump_opts.omit_nil ? Qtrue : Qfalse);
321
324
  rb_hash_aset(opts, oj_hash_class_sym, oj_default_options.hash_class);
322
325
  rb_hash_aset(opts, oj_array_class_sym, oj_default_options.array_class);
323
-
326
+
327
+ if (NULL == oj_default_options.ignore) {
328
+ rb_hash_aset(opts, ignore_sym, Qnil);
329
+ } else {
330
+ VALUE *vp;
331
+ volatile VALUE a = rb_ary_new();
332
+
333
+ for (vp = oj_default_options.ignore; Qnil != *vp; vp++) {
334
+ rb_ary_push(a, *vp);
335
+ }
336
+ rb_hash_aset(opts, ignore_sym, a);
337
+ }
324
338
  return opts;
325
339
  }
326
340
 
@@ -358,6 +372,7 @@ get_def_opts(VALUE self) {
358
372
  * - *:hash_class* [_Class_|_nil_] Class to use instead of Hash on load, :object_class can also be used.
359
373
  * - *:array_class* [_Class_|_nil_] Class to use instead of Array on load.
360
374
  * - *:omit_nil* [_true_|_false_] if true Hash and Object attributes with nil values are omitted.
375
+ * - *:ignore* [_nil_|Array] either nil or an Array of classes to ignore when dumping
361
376
  */
362
377
  static VALUE
363
378
  set_def_opts(VALUE self, VALUE opts) {
@@ -672,6 +687,25 @@ oj_parse_options(VALUE ropts, Options copts) {
672
687
  }
673
688
  }
674
689
  oj_parse_opt_match_string(&copts->str_rx, ropts);
690
+ if (Qtrue == rb_funcall(ropts, oj_has_key_id, 1, ignore_sym)) {
691
+ xfree(copts->ignore);
692
+ copts->ignore = NULL;
693
+ if (Qnil != (v = rb_hash_lookup(ropts, ignore_sym))) {
694
+ int cnt;
695
+
696
+ rb_check_type(v, T_ARRAY);
697
+ cnt = (int)RARRAY_LEN(v);
698
+ if (0 < cnt) {
699
+ int i;
700
+
701
+ copts->ignore = ALLOC_N(VALUE, cnt + 1);
702
+ for (i = 0; i < cnt; i++) {
703
+ copts->ignore[i] = rb_ary_entry(v, i);
704
+ }
705
+ copts->ignore[i] = Qnil;
706
+ }
707
+ }
708
+ }
675
709
  }
676
710
 
677
711
  static int
@@ -1604,6 +1638,7 @@ Init_oj() {
1604
1638
  float_prec_sym = ID2SYM(rb_intern("float_precision")); rb_gc_register_address(&float_prec_sym);
1605
1639
  float_sym = ID2SYM(rb_intern("float")); rb_gc_register_address(&float_sym);
1606
1640
  huge_sym = ID2SYM(rb_intern("huge")); rb_gc_register_address(&huge_sym);
1641
+ ignore_sym = ID2SYM(rb_intern("ignore")); rb_gc_register_address(&ignore_sym);
1607
1642
  json_sym = ID2SYM(rb_intern("json")); rb_gc_register_address(&json_sym);
1608
1643
  match_string_sym = ID2SYM(rb_intern("match_string")); rb_gc_register_address(&match_string_sym);
1609
1644
  mode_sym = ID2SYM(rb_intern("mode")); rb_gc_register_address(&mode_sym);
@@ -161,6 +161,7 @@ typedef struct _Options {
161
161
  VALUE array_class; // class to use in place of Array on load
162
162
  struct _DumpOpts dump_opts;
163
163
  struct _RxClass str_rx;
164
+ VALUE *ignore; // Qnil terminated array of classes or NULL
164
165
  } *Options;
165
166
 
166
167
  struct _Out;
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '3.3.10'
4
+ VERSION = '3.4.0'
5
5
  end
@@ -104,6 +104,7 @@ information.
104
104
  | :escape_mode | Symbol | | | | | | x | |
105
105
  | :float_precision | Fixnum | x | x | | | | x | |
106
106
  | :hash_class | Class | | | x | x | | x | |
107
+ | :ignore | Array | | | | | x | x | |
107
108
  | :indent | Integer | x | x | 3 | 4 | x | x | x |
108
109
  | :indent_str | String | | | x | x | | x | |
109
110
  | :match_string | Hash | | | x | x | | x | |
@@ -130,6 +130,11 @@ The number of digits of precision when dumping floats, 0 indicates use Ruby dire
130
130
 
131
131
  Class to use instead of Hash on load. This is the same as the :object_class.
132
132
 
133
+ ### :ignore [Array]
134
+
135
+ Ignore all the classes in the Array when dumping. A value of nil indicates
136
+ ignore nothing.
137
+
133
138
  ### :indent [Fixnum]
134
139
 
135
140
  Number of spaces to indent each element in a JSON document, zero is no newline
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: UTF-8
2
+ # encoding: utf-8
3
3
 
4
4
  $: << File.dirname(__FILE__)
5
5
 
@@ -761,6 +761,15 @@ class ObjectJuice < Minitest::Test
761
761
  assert_equal(obj, obj2)
762
762
  end
763
763
 
764
+ def test_ignore
765
+ obj = Jeez.new(true, 58)
766
+ json = Oj.dump({ 'a' => 7, 'b' => obj }, :mode => :object, :indent => 2, :ignore => [ Jeez ])
767
+ assert_equal(%|{
768
+ "a":7
769
+ }
770
+ |, json)
771
+ end
772
+
764
773
  def test_exception
765
774
  err = nil
766
775
  begin
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: UTF-8
2
+ # encoding: utf-8
3
3
 
4
4
  $: << File.dirname(__FILE__)
5
5
 
@@ -154,6 +154,7 @@ class Juice < Minitest::Test
154
154
  :omit_nil=>false,
155
155
  :allow_nan=>true,
156
156
  :array_class=>Array,
157
+ :ignore=>nil,
157
158
  }
158
159
  Oj.default_options = alt
159
160
  #keys = alt.keys
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.3.10
4
+ version: 3.4.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-12-30 00:00:00.000000000 Z
11
+ date: 2018-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -80,15 +80,15 @@ extensions:
80
80
  extra_rdoc_files:
81
81
  - README.md
82
82
  - pages/Advanced.md
83
- - pages/Compatibility.md
84
- - pages/Custom.md
83
+ - pages/WAB.md
85
84
  - pages/Encoding.md
86
- - pages/JsonGem.md
87
85
  - pages/Modes.md
88
- - pages/Options.md
89
- - pages/Rails.md
90
86
  - pages/Security.md
91
- - pages/WAB.md
87
+ - pages/JsonGem.md
88
+ - pages/Rails.md
89
+ - pages/Compatibility.md
90
+ - pages/Custom.md
91
+ - pages/Options.md
92
92
  files:
93
93
  - LICENSE
94
94
  - README.md
@@ -172,7 +172,6 @@ files:
172
172
  - test/activesupport5/encoding_test_cases.rb
173
173
  - test/activesupport5/test_helper.rb
174
174
  - test/activesupport5/time_zone_test_helpers.rb
175
- - test/bug.rb
176
175
  - test/files.rb
177
176
  - test/helper.rb
178
177
  - test/isolated/shared.rb
@@ -265,78 +264,77 @@ signing_key:
265
264
  specification_version: 4
266
265
  summary: A fast JSON parser and serializer.
267
266
  test_files:
268
- - test/_test_active.rb
269
- - test/_test_active_mimic.rb
270
- - test/_test_mimic_rails.rb
271
- - test/activesupport4/decoding_test.rb
272
- - test/activesupport4/encoding_test.rb
273
- - test/activesupport4/test_helper.rb
274
- - test/activesupport5/decoding_test.rb
275
- - test/activesupport5/encoding_test.rb
276
- - test/activesupport5/encoding_test_cases.rb
277
267
  - test/activesupport5/test_helper.rb
278
268
  - test/activesupport5/time_zone_test_helpers.rb
279
- - test/bug.rb
269
+ - test/activesupport5/decoding_test.rb
270
+ - test/activesupport5/encoding_test_cases.rb
271
+ - test/activesupport5/encoding_test.rb
272
+ - test/test_file.rb
280
273
  - test/files.rb
281
- - test/helper.rb
282
- - test/isolated/shared.rb
283
- - test/isolated/test_mimic_after.rb
284
- - test/isolated/test_mimic_alone.rb
285
- - test/isolated/test_mimic_as_json.rb
286
- - test/isolated/test_mimic_before.rb
287
- - test/isolated/test_mimic_define.rb
288
- - test/isolated/test_mimic_rails_after.rb
289
- - test/isolated/test_mimic_rails_before.rb
290
- - test/isolated/test_mimic_redefine.rb
291
- - test/json_gem/json_addition_test.rb
292
- - test/json_gem/json_common_interface_test.rb
293
- - test/json_gem/json_encoding_test.rb
294
- - test/json_gem/json_ext_parser_test.rb
295
- - test/json_gem/json_fixtures_test.rb
296
- - test/json_gem/json_generator_test.rb
297
- - test/json_gem/json_generic_object_test.rb
298
- - test/json_gem/json_parser_test.rb
299
- - test/json_gem/json_string_matching_test.rb
300
- - test/json_gem/test_helper.rb
301
- - test/perf.rb
302
- - test/perf_compat.rb
303
- - test/perf_fast.rb
304
- - test/perf_file.rb
305
- - test/perf_object.rb
306
- - test/perf_saj.rb
307
274
  - test/perf_scp.rb
308
- - test/perf_simple.rb
309
- - test/perf_strict.rb
310
- - test/perf_wab.rb
311
- - test/sample/change.rb
312
- - test/sample/dir.rb
313
- - test/sample/doc.rb
275
+ - test/test_debian.rb
276
+ - test/test_gc.rb
277
+ - test/_test_mimic_rails.rb
278
+ - test/test_writer.rb
279
+ - test/test_hash.rb
314
280
  - test/sample/file.rb
315
- - test/sample/group.rb
316
281
  - test/sample/hasprops.rb
317
282
  - test/sample/layer.rb
318
- - test/sample/line.rb
283
+ - test/sample/change.rb
284
+ - test/sample/doc.rb
319
285
  - test/sample/oval.rb
320
- - test/sample/rect.rb
321
286
  - test/sample/shape.rb
322
287
  - test/sample/text.rb
323
- - test/sample.rb
324
- - test/sample_json.rb
325
- - test/test_compat.rb
326
- - test/test_custom.rb
327
- - test/test_debian.rb
328
- - test/test_fast.rb
329
- - test/test_file.rb
330
- - test/test_gc.rb
331
- - test/test_hash.rb
332
- - test/test_null.rb
288
+ - test/sample/group.rb
289
+ - test/sample/dir.rb
290
+ - test/sample/line.rb
291
+ - test/sample/rect.rb
292
+ - test/tests.rb
333
293
  - test/test_object.rb
294
+ - test/perf_wab.rb
295
+ - test/tests_mimic.rb
296
+ - test/perf_saj.rb
297
+ - test/tests_mimic_addition.rb
334
298
  - test/test_saj.rb
299
+ - test/sample.rb
335
300
  - test/test_scp.rb
336
- - test/test_strict.rb
337
- - test/test_various.rb
301
+ - test/perf_object.rb
302
+ - test/perf_simple.rb
303
+ - test/test_null.rb
304
+ - test/_test_active_mimic.rb
305
+ - test/_test_active.rb
306
+ - test/test_compat.rb
307
+ - test/sample_json.rb
308
+ - test/json_gem/test_helper.rb
309
+ - test/json_gem/json_generic_object_test.rb
310
+ - test/json_gem/json_common_interface_test.rb
311
+ - test/json_gem/json_string_matching_test.rb
312
+ - test/json_gem/json_addition_test.rb
313
+ - test/json_gem/json_fixtures_test.rb
314
+ - test/json_gem/json_generator_test.rb
315
+ - test/json_gem/json_ext_parser_test.rb
316
+ - test/json_gem/json_parser_test.rb
317
+ - test/json_gem/json_encoding_test.rb
318
+ - test/helper.rb
319
+ - test/activesupport4/test_helper.rb
320
+ - test/activesupport4/decoding_test.rb
321
+ - test/activesupport4/encoding_test.rb
338
322
  - test/test_wab.rb
339
- - test/test_writer.rb
340
- - test/tests.rb
341
- - test/tests_mimic.rb
342
- - test/tests_mimic_addition.rb
323
+ - test/perf_file.rb
324
+ - test/perf_compat.rb
325
+ - test/test_various.rb
326
+ - test/test_strict.rb
327
+ - test/test_custom.rb
328
+ - test/perf_strict.rb
329
+ - test/perf_fast.rb
330
+ - test/isolated/test_mimic_alone.rb
331
+ - test/isolated/test_mimic_after.rb
332
+ - test/isolated/test_mimic_as_json.rb
333
+ - test/isolated/test_mimic_rails_after.rb
334
+ - test/isolated/test_mimic_before.rb
335
+ - test/isolated/test_mimic_rails_before.rb
336
+ - test/isolated/test_mimic_define.rb
337
+ - test/isolated/shared.rb
338
+ - test/isolated/test_mimic_redefine.rb
339
+ - test/perf.rb
340
+ - test/test_fast.rb
@@ -1,25 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- %w(lib ext test).each do |dir|
5
- $LOAD_PATH.unshift File.expand_path("../../#{dir}", __FILE__)
6
- end
7
-
8
- require 'rails'
9
- require 'active_support'
10
- require 'active_support/json'
11
- require 'oj'
12
-
13
- x = {"a": BigDecimal("1.1"), "t": Time.now}
14
-
15
- #ActiveSupport.encode_big_decimal_as_string = false
16
-
17
- Oj.optimize_rails
18
-
19
- puts "to_json #{x.to_json}"
20
-
21
- Oj.default_options = { bigdecimal_as_decimal: true}
22
- #puts Oj.default_options
23
-
24
- puts "to_json #{x.to_json}"
25
-