oj 3.0.6 → 3.0.7

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: 5d2a2d3b4fd246384540dcb2b35b335bddd57388
4
- data.tar.gz: 89b10cb944cf00447fcc96cadcc4098c6fbd88df
3
+ metadata.gz: 5a9a1e933a2b0c03c3fb9c0e0b8ef0447edf2438
4
+ data.tar.gz: 588b81842eb490fd7beb6021a048f7703ddeb28a
5
5
  SHA512:
6
- metadata.gz: 826667035ad04a8e76a63e9d1ada8ead7c3d2f7d3f83876a28d6cec476cdf8cb4bfd57f61d3607ea2bb9edd489b6d619b27b0299d89466cafd71f25e5a744240
7
- data.tar.gz: 8a6d58b91255b62fe651a5dee8eb8f302ec20a60cf900061ec8dfdcd7bda5fcf331e68eca9416efbf8068fdc0b05d77c17e3360c70d7a376d32cebbc8e4030bb
6
+ metadata.gz: e74ce695c617c00f6124a523294f949eb291b6c80f8da2c1e122d088b0c381473142bb3650ddd634693458c2356f37185ecebb03adf4c682e5337cbccf1b10de
7
+ data.tar.gz: e8eb16851a194c06a5a41527c63c149001bee902132e4591fbf3f46544b17ec942924ca5e5f7abf7bda5cc4fcf24623c1dd03c12afc9525561f52231b68486e8
@@ -421,7 +421,35 @@ oj_mimic_generate(int argc, VALUE *argv, VALUE self) {
421
421
  VALUE
422
422
  oj_mimic_pretty_generate(int argc, VALUE *argv, VALUE self) {
423
423
  struct _Options copts = oj_default_options;
424
-
424
+ VALUE rargs[2];
425
+ volatile VALUE h;
426
+
427
+ // Some (all?) json gem to_json methods need a State instance and not just
428
+ // a Hash. I haven't dug deep enough to find out why but using a State
429
+ // instance and not a Hash gives the desired behavior.
430
+ *rargs = *argv;
431
+ if (1 == argc) {
432
+ h = rb_hash_new();
433
+ } else {
434
+ h = argv[1];
435
+ }
436
+ if (Qfalse == rb_funcall(h, oj_has_key_id, 1, oj_indent_sym)) {
437
+ rb_hash_aset(h, oj_indent_sym, rb_str_new2(" "));
438
+ }
439
+ if (Qfalse == rb_funcall(h, oj_has_key_id, 1, oj_space_before_sym)) {
440
+ rb_hash_aset(h, oj_space_before_sym, rb_str_new2(""));
441
+ }
442
+ if (Qfalse == rb_funcall(h, oj_has_key_id, 1, oj_space_sym)) {
443
+ rb_hash_aset(h, oj_space_sym, rb_str_new2(" "));
444
+ }
445
+ if (Qfalse == rb_funcall(h, oj_has_key_id, 1, oj_object_nl_sym)) {
446
+ rb_hash_aset(h, oj_object_nl_sym, rb_str_new2("\n"));
447
+ }
448
+ if (Qfalse == rb_funcall(h, oj_has_key_id, 1, oj_array_nl_sym)) {
449
+ rb_hash_aset(h, oj_array_nl_sym, rb_str_new2("\n"));
450
+ }
451
+ rargs[1] = rb_funcall(state_class, oj_new_id, 1, h);
452
+
425
453
  copts.str_rx.head = NULL;
426
454
  copts.str_rx.tail = NULL;
427
455
  strcpy(copts.dump_opts.indent_str, " ");
@@ -436,7 +464,7 @@ oj_mimic_pretty_generate(int argc, VALUE *argv, VALUE self) {
436
464
  copts.dump_opts.array_size = (uint8_t)strlen(copts.dump_opts.array_nl);
437
465
  copts.dump_opts.use = true;
438
466
 
439
- return mimic_generate_core(argc, argv, &copts);
467
+ return mimic_generate_core(2, rargs, &copts);
440
468
  }
441
469
 
442
470
  static VALUE
@@ -1340,6 +1340,13 @@ extern VALUE oj_define_mimic_json(int argc, VALUE *argv, VALUE self);
1340
1340
  */
1341
1341
  extern VALUE oj_mimic_generate(int argc, VALUE *argv, VALUE self);
1342
1342
 
1343
+ /* Document-module: Oj.optimize_rails()
1344
+ *
1345
+ * Sets the Oj as the Rails encoder and decoder. Oj::Rails.optimize is also
1346
+ * called.
1347
+ */
1348
+ extern VALUE oj_optimize_rails(VALUE self);
1349
+
1343
1350
  /*
1344
1351
  extern void oj_hash_test();
1345
1352
 
@@ -324,17 +324,29 @@ dump_to_s(VALUE obj, int depth, Out out, bool as_ok) {
324
324
  oj_dump_cstr(rb_string_value_ptr((VALUE*)&rstr), RSTRING_LEN(rstr), 0, 0, out);
325
325
  }
326
326
 
327
+ static ID parameters_id = 0;
328
+
329
+ static void
330
+ dump_actioncontroller_parameters(VALUE obj, int depth, Out out, bool as_ok) {
331
+ if (0 == parameters_id) {
332
+ parameters_id = rb_intern("@parameters");
333
+ }
334
+ out->argc = 0;
335
+ dump_rails_val(rb_ivar_get(obj, parameters_id), depth, out, true);
336
+ }
337
+
327
338
  typedef struct _NamedFunc {
328
339
  const char *name;
329
340
  DumpFunc func;
330
341
  } *NamedFunc;
331
342
 
332
343
  static struct _NamedFunc dump_map[] = {
344
+ { "ActionController::Parameters", dump_actioncontroller_parameters },
345
+ { "ActiveSupport::TimeWithZone", dump_timewithzone },
333
346
  { "BigDecimal", dump_bigdecimal },
334
347
  { "Range", dump_to_s },
335
348
  { "Regexp", dump_to_s },
336
349
  { "Time", dump_time },
337
- { "ActiveSupport::TimeWithZone", dump_timewithzone },
338
350
  { NULL, NULL },
339
351
  };
340
352
 
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '3.0.6'
4
+ VERSION = '3.0.7'
5
5
  end
@@ -10,7 +10,13 @@ require 'oj'
10
10
 
11
11
  Oj::Rails.set_encoder()
12
12
  Oj::Rails.set_decoder()
13
- Oj::Rails.optimize(Array, BigDecimal, Hash, Range, Regexp, Time, ActiveSupport::TimeWithZone)
13
+ Oj::Rails.optimize()
14
+ ```
15
+
16
+ or simply call
17
+
18
+ ```ruby
19
+ Oj.optimize_rails()
14
20
  ```
15
21
 
16
22
  Some of the Oj options are supported as arguments to the encoder if called
@@ -47,10 +53,11 @@ optimized version is the same as the ActiveSupport default encoding for a
47
53
  given class. The optimized versions are toggled with the optimize() and
48
54
  deoptimize() methods. There is a default optimized version for every class
49
55
  that takes the visible attributes and encodes them but that may not be the
50
- same as what Rails uses. Trial an error is the best approach for classes not
56
+ same as what Rails uses. Trial and error is the best approach for classes not
51
57
  listed here.
52
58
 
53
- The classes that can be put in optimized mode are:
59
+ The classes that can be put in optimized mode and are optimized when
60
+ Oj::Rails.optimize is called with no arguments are:
54
61
 
55
62
  * Array
56
63
  * BigDecimal
@@ -59,6 +66,7 @@ The classes that can be put in optimized mode are:
59
66
  * Regexp
60
67
  * Time
61
68
  * ActiveSupport::TimeWithZone
69
+ * ActionController::Parameters
62
70
  * any class inheriting from ActiveRecord::Base
63
71
  * any other class where all attributes should be dumped
64
72
 
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.6
4
+ version: 3.0.7
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-05-07 00:00:00.000000000 Z
11
+ date: 2017-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -60,14 +60,14 @@ extensions:
60
60
  extra_rdoc_files:
61
61
  - README.md
62
62
  - pages/Advanced.md
63
- - pages/Encoding.md
64
- - pages/Modes.md
65
- - pages/Security.md
66
- - pages/JsonGem.md
67
- - pages/Rails.md
68
63
  - pages/Compatibility.md
69
64
  - pages/Custom.md
65
+ - pages/Encoding.md
66
+ - pages/JsonGem.md
67
+ - pages/Modes.md
70
68
  - pages/Options.md
69
+ - pages/Rails.md
70
+ - pages/Security.md
71
71
  files:
72
72
  - LICENSE
73
73
  - README.md
@@ -239,75 +239,75 @@ signing_key:
239
239
  specification_version: 4
240
240
  summary: A fast JSON parser and serializer.
241
241
  test_files:
242
- - test/activesupport5/test_helper.rb
243
- - test/activesupport5/time_zone_test_helpers.rb
242
+ - test/_test_active.rb
243
+ - test/_test_active_mimic.rb
244
+ - test/_test_mimic_rails.rb
245
+ - test/activesupport4/decoding_test.rb
246
+ - test/activesupport4/encoding_test.rb
247
+ - test/activesupport4/test_helper.rb
244
248
  - test/activesupport5/decoding_test.rb
245
- - test/activesupport5/encoding_test_cases.rb
246
249
  - test/activesupport5/encoding_test.rb
247
- - test/test_file.rb
250
+ - test/activesupport5/encoding_test_cases.rb
251
+ - test/activesupport5/test_helper.rb
252
+ - test/activesupport5/time_zone_test_helpers.rb
248
253
  - test/files.rb
254
+ - test/helper.rb
255
+ - test/isolated/shared.rb
256
+ - test/isolated/test_mimic_after.rb
257
+ - test/isolated/test_mimic_alone.rb
258
+ - test/isolated/test_mimic_as_json.rb
259
+ - test/isolated/test_mimic_before.rb
260
+ - test/isolated/test_mimic_define.rb
261
+ - test/isolated/test_mimic_rails_after.rb
262
+ - test/isolated/test_mimic_rails_before.rb
263
+ - test/isolated/test_mimic_redefine.rb
264
+ - test/json_gem/json_addition_test.rb
265
+ - test/json_gem/json_common_interface_test.rb
266
+ - test/json_gem/json_encoding_test.rb
267
+ - test/json_gem/json_ext_parser_test.rb
268
+ - test/json_gem/json_fixtures_test.rb
269
+ - test/json_gem/json_generator_test.rb
270
+ - test/json_gem/json_generic_object_test.rb
271
+ - test/json_gem/json_parser_test.rb
272
+ - test/json_gem/json_string_matching_test.rb
273
+ - test/json_gem/test_helper.rb
274
+ - test/perf.rb
275
+ - test/perf_compat.rb
276
+ - test/perf_fast.rb
277
+ - test/perf_file.rb
278
+ - test/perf_object.rb
279
+ - test/perf_saj.rb
249
280
  - test/perf_scp.rb
250
- - test/test_debian.rb
251
- - test/test_gc.rb
252
- - test/_test_mimic_rails.rb
253
- - test/test_writer.rb
254
- - test/test_hash.rb
281
+ - test/perf_simple.rb
282
+ - test/perf_strict.rb
283
+ - test/sample/change.rb
284
+ - test/sample/dir.rb
285
+ - test/sample/doc.rb
255
286
  - test/sample/file.rb
287
+ - test/sample/group.rb
256
288
  - test/sample/hasprops.rb
257
289
  - test/sample/layer.rb
258
- - test/sample/change.rb
259
- - test/sample/doc.rb
290
+ - test/sample/line.rb
260
291
  - test/sample/oval.rb
292
+ - test/sample/rect.rb
261
293
  - test/sample/shape.rb
262
294
  - test/sample/text.rb
263
- - test/sample/group.rb
264
- - test/sample/dir.rb
265
- - test/sample/line.rb
266
- - test/sample/rect.rb
267
- - test/tests.rb
268
- - test/test_object.rb
269
- - test/tests_mimic.rb
270
- - test/perf_saj.rb
271
- - test/tests_mimic_addition.rb
272
- - test/test_saj.rb
273
295
  - test/sample.rb
274
- - test/test_scp.rb
275
- - test/perf_object.rb
276
- - test/perf_simple.rb
277
- - test/test_null.rb
278
- - test/_test_active_mimic.rb
279
- - test/_test_active.rb
280
- - test/test_compat.rb
281
296
  - test/sample_json.rb
282
- - test/json_gem/test_helper.rb
283
- - test/json_gem/json_generic_object_test.rb
284
- - test/json_gem/json_common_interface_test.rb
285
- - test/json_gem/json_string_matching_test.rb
286
- - test/json_gem/json_addition_test.rb
287
- - test/json_gem/json_fixtures_test.rb
288
- - test/json_gem/json_generator_test.rb
289
- - test/json_gem/json_ext_parser_test.rb
290
- - test/json_gem/json_parser_test.rb
291
- - test/json_gem/json_encoding_test.rb
292
- - test/helper.rb
293
- - test/activesupport4/test_helper.rb
294
- - test/activesupport4/decoding_test.rb
295
- - test/activesupport4/encoding_test.rb
296
- - test/perf_file.rb
297
- - test/perf_compat.rb
298
- - test/test_various.rb
299
- - test/test_strict.rb
297
+ - test/test_compat.rb
300
298
  - test/test_custom.rb
301
- - test/perf_strict.rb
302
- - test/perf_fast.rb
303
- - test/isolated/test_mimic_alone.rb
304
- - test/isolated/test_mimic_after.rb
305
- - test/isolated/test_mimic_as_json.rb
306
- - test/isolated/test_mimic_rails_after.rb
307
- - test/isolated/test_mimic_before.rb
308
- - test/isolated/test_mimic_rails_before.rb
309
- - test/isolated/test_mimic_define.rb
310
- - test/isolated/shared.rb
311
- - test/isolated/test_mimic_redefine.rb
312
- - test/perf.rb
299
+ - test/test_debian.rb
313
300
  - test/test_fast.rb
301
+ - test/test_file.rb
302
+ - test/test_gc.rb
303
+ - test/test_hash.rb
304
+ - test/test_null.rb
305
+ - test/test_object.rb
306
+ - test/test_saj.rb
307
+ - test/test_scp.rb
308
+ - test/test_strict.rb
309
+ - test/test_various.rb
310
+ - test/test_writer.rb
311
+ - test/tests.rb
312
+ - test/tests_mimic.rb
313
+ - test/tests_mimic_addition.rb