oj 3.5.1 → 3.6.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
  SHA256:
3
- metadata.gz: '09deb70b3ba1d0eeac19e27fd57ef92437f44aff2bf1bcdc8d6c46f523da195e'
4
- data.tar.gz: 0154fb4466a7f286428685e851029bb48e6d82ffb2b25cf34cf82541fd8b5c38
3
+ metadata.gz: c39b2eaf82ca583abb1636a96c5b68c87d870243f1857fb3901fa653f5699336
4
+ data.tar.gz: ad6b0824c146f26271c212fae1f27b359c692ca36f554e499b9a9b56c753c999
5
5
  SHA512:
6
- metadata.gz: e6fe3ca939fae01ee40793c523a366bbb307db771ef26d4157c597e517610d6c627ab96ea9daa68cccd9c2c3054cc2cc46992f295e511cfb5388e664e3a3fa62
7
- data.tar.gz: 6f013fa5478f633ee16c6f557ca565b25fa605d05d9d59ae373b78a7bd8dc216d2af938f98b249abc8df20729a33df1c5b8be85a18a50046235800007a44989d
6
+ metadata.gz: 6344b7a10952348c49e21d85779dd9a4fd25c81566594a34945f3e81785bab6449ad015ad4fe1f9bf8d0cb5acfe20ce6eba2f228dae6a76f085e2531b5b93f5a
7
+ data.tar.gz: 8f21dd978b252c74315f8988c0352d771c683dcddb340fbdbfa800a249c9187ec622d9e3bb7dfbd76d61b8c1ee1e8709494b69feecea50a97251ab5bfb5fdc52
@@ -336,6 +336,11 @@ dump_to_s(VALUE obj, int depth, Out out, bool as_ok) {
336
336
 
337
337
  static ID parameters_id = 0;
338
338
 
339
+ typedef struct _StrLen {
340
+ const char *str;
341
+ int len;
342
+ } *StrLen;
343
+
339
344
  static void
340
345
  dump_actioncontroller_parameters(VALUE obj, int depth, Out out, bool as_ok) {
341
346
  if (0 == parameters_id) {
@@ -345,6 +350,153 @@ dump_actioncontroller_parameters(VALUE obj, int depth, Out out, bool as_ok) {
345
350
  dump_rails_val(rb_ivar_get(obj, parameters_id), depth, out, true);
346
351
  }
347
352
 
353
+ static StrLen
354
+ columns_array(VALUE rcols, int *ccnt) {
355
+ volatile VALUE v;
356
+ StrLen cp;
357
+ StrLen cols;
358
+ int i;
359
+ int cnt = (int)RARRAY_LEN(rcols);
360
+
361
+ *ccnt = cnt;
362
+ cols = ALLOC_N(struct _StrLen, cnt);
363
+ for (i = 0, cp = cols; i < cnt; i++, cp++) {
364
+ v = rb_ary_entry(rcols, i);
365
+ if (T_STRING != rb_type(v)) {
366
+ v = rb_funcall(v, oj_to_s_id, 0);
367
+ }
368
+ cp->str = StringValuePtr(v);
369
+ cp->len = (int)RSTRING_LEN(v);
370
+ }
371
+ return cols;
372
+ }
373
+
374
+ static void
375
+ dump_row(VALUE row, StrLen cols, int ccnt, int depth, Out out) {
376
+ size_t size;
377
+ int d2 = depth + 1;
378
+ int i;
379
+
380
+ assure_size(out, 2);
381
+ *out->cur++ = '{';
382
+ size = depth * out->indent + 3;
383
+ for (i = 0; i < ccnt; i++, cols++) {
384
+ assure_size(out, size);
385
+ if (out->opts->dump_opts.use) {
386
+ if (0 < out->opts->dump_opts.array_size) {
387
+ strcpy(out->cur, out->opts->dump_opts.array_nl);
388
+ out->cur += out->opts->dump_opts.array_size;
389
+ }
390
+ if (0 < out->opts->dump_opts.indent_size) {
391
+ int i;
392
+ for (i = d2; 0 < i; i--) {
393
+ strcpy(out->cur, out->opts->dump_opts.indent_str);
394
+ out->cur += out->opts->dump_opts.indent_size;
395
+ }
396
+ }
397
+ } else {
398
+ fill_indent(out, d2);
399
+ }
400
+ oj_dump_cstr(cols->str, cols->len, 0, 0, out);
401
+ *out->cur++ = ':';
402
+ dump_rails_val(rb_ary_entry(row, i), depth, out, true);
403
+ if (i < ccnt - 1) {
404
+ *out->cur++ = ',';
405
+ }
406
+ }
407
+ size = depth * out->indent + 1;
408
+ assure_size(out, size);
409
+ if (out->opts->dump_opts.use) {
410
+ if (0 < out->opts->dump_opts.array_size) {
411
+ strcpy(out->cur, out->opts->dump_opts.array_nl);
412
+ out->cur += out->opts->dump_opts.array_size;
413
+ }
414
+ if (0 < out->opts->dump_opts.indent_size) {
415
+ int i;
416
+
417
+ for (i = depth; 0 < i; i--) {
418
+ strcpy(out->cur, out->opts->dump_opts.indent_str);
419
+ out->cur += out->opts->dump_opts.indent_size;
420
+ }
421
+ }
422
+ } else {
423
+ fill_indent(out, depth);
424
+ }
425
+ *out->cur++ = '}';
426
+ }
427
+
428
+ static ID rows_id = 0;
429
+ static ID columns_id = 0;
430
+
431
+ static void
432
+ dump_activerecord_result(VALUE obj, int depth, Out out, bool as_ok) {
433
+ volatile VALUE rows;
434
+ StrLen cols;
435
+ int ccnt = 0;
436
+ int i, rcnt;
437
+ size_t size;
438
+ int d2 = depth + 1;
439
+
440
+ if (0 == rows_id) {
441
+ rows_id = rb_intern("@rows");
442
+ columns_id = rb_intern("@columns");
443
+ }
444
+ out->argc = 0;
445
+ cols = columns_array(rb_ivar_get(obj, columns_id), &ccnt);
446
+ rows = rb_ivar_get(obj, rows_id);
447
+ rcnt = RARRAY_LEN(rows);
448
+ assure_size(out, 2);
449
+ *out->cur++ = '[';
450
+ if (out->opts->dump_opts.use) {
451
+ size = d2 * out->opts->dump_opts.indent_size + out->opts->dump_opts.array_size + 1;
452
+ } else {
453
+ size = d2 * out->indent + 2;
454
+ }
455
+ assure_size(out, 2);
456
+ for (i = 0; i < rcnt; i++) {
457
+ assure_size(out, size);
458
+ if (out->opts->dump_opts.use) {
459
+ if (0 < out->opts->dump_opts.array_size) {
460
+ strcpy(out->cur, out->opts->dump_opts.array_nl);
461
+ out->cur += out->opts->dump_opts.array_size;
462
+ }
463
+ if (0 < out->opts->dump_opts.indent_size) {
464
+ int i;
465
+ for (i = d2; 0 < i; i--) {
466
+ strcpy(out->cur, out->opts->dump_opts.indent_str);
467
+ out->cur += out->opts->dump_opts.indent_size;
468
+ }
469
+ }
470
+ } else {
471
+ fill_indent(out, d2);
472
+ }
473
+ dump_row(rb_ary_entry(rows, i), cols, ccnt, d2, out);
474
+ if (i < rcnt - 1) {
475
+ *out->cur++ = ',';
476
+ }
477
+ }
478
+ xfree(cols);
479
+ size = depth * out->indent + 1;
480
+ assure_size(out, size);
481
+ if (out->opts->dump_opts.use) {
482
+ if (0 < out->opts->dump_opts.array_size) {
483
+ strcpy(out->cur, out->opts->dump_opts.array_nl);
484
+ out->cur += out->opts->dump_opts.array_size;
485
+ }
486
+ if (0 < out->opts->dump_opts.indent_size) {
487
+ int i;
488
+
489
+ for (i = depth; 0 < i; i--) {
490
+ strcpy(out->cur, out->opts->dump_opts.indent_str);
491
+ out->cur += out->opts->dump_opts.indent_size;
492
+ }
493
+ }
494
+ } else {
495
+ fill_indent(out, depth);
496
+ }
497
+ *out->cur++ = ']';
498
+ }
499
+
348
500
  typedef struct _NamedFunc {
349
501
  const char *name;
350
502
  DumpFunc func;
@@ -352,6 +504,7 @@ typedef struct _NamedFunc {
352
504
 
353
505
  static struct _NamedFunc dump_map[] = {
354
506
  { "ActionController::Parameters", dump_actioncontroller_parameters },
507
+ { "ActiveRecord::Result", dump_activerecord_result },
355
508
  { "ActiveSupport::TimeWithZone", dump_timewithzone },
356
509
  { "BigDecimal", dump_bigdecimal },
357
510
  { "Range", dump_to_s },
@@ -36,7 +36,7 @@ void
36
36
  oj_trace_parse_call(const char *func, ParseInfo pi, const char *file, int line, VALUE obj) {
37
37
  char fmt[64];
38
38
  char indent[MAX_INDENT];
39
- int depth = stack_size(&pi->stack) * 2;
39
+ int depth = (int)(stack_size(&pi->stack) * 2);
40
40
 
41
41
  fill_indent(indent, depth);
42
42
  sprintf(fmt, "#0:%%13s:%%3d:Oj:-:%%%ds %%s %%s\n", depth);
@@ -47,7 +47,7 @@ void
47
47
  oj_trace_parse_in(const char *func, ParseInfo pi, const char *file, int line) {
48
48
  char fmt[64];
49
49
  char indent[MAX_INDENT];
50
- int depth = stack_size(&pi->stack) * 2;
50
+ int depth = (int)(stack_size(&pi->stack) * 2);
51
51
 
52
52
  fill_indent(indent, depth);
53
53
  sprintf(fmt, "#0:%%13s:%%3d:Oj:}:%%%ds %%s\n", depth);
@@ -58,7 +58,7 @@ void
58
58
  oj_trace_parse_hash_end(ParseInfo pi, const char *file, int line) {
59
59
  char fmt[64];
60
60
  char indent[MAX_INDENT];
61
- int depth = stack_size(&pi->stack) * 2 - 2;
61
+ int depth = (int)(stack_size(&pi->stack) * 2 - 2);
62
62
  Val v = stack_peek(&pi->stack);
63
63
  VALUE obj = v->val;
64
64
 
@@ -71,7 +71,7 @@ void
71
71
  oj_trace_parse_array_end(ParseInfo pi, const char *file, int line) {
72
72
  char fmt[64];
73
73
  char indent[MAX_INDENT];
74
- int depth = stack_size(&pi->stack) * 2;
74
+ int depth = (int)(stack_size(&pi->stack) * 2);
75
75
 
76
76
  fill_indent(indent, depth);
77
77
  sprintf(fmt, "#0:%%13s:%%3d:Oj:{:%%%ds array_ned\n", depth);
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '3.5.1'
4
+ VERSION = '3.6.0'
5
5
  end
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.dirname(__FILE__)
4
+ $: << File.dirname(File.dirname(__FILE__))
5
+
6
+ require 'helper'
7
+ require "rails/all"
8
+
9
+ Oj::Rails.set_encoder()
10
+ Oj::Rails.optimize()
11
+
12
+ Oj.default_options = { mode: :rails }
13
+
14
+ class ActiveRecordResultTest < Minitest::Test
15
+ def test_hash_rows
16
+
17
+ result = ActiveRecord::Result.new(["one", "two"],
18
+ [
19
+ ["row 1 col 1", "row 1 col 2"],
20
+ ["row 2 col 1", "row 2 col 2"],
21
+ ["row 3 col 1", "row 3 col 2"],
22
+ ])
23
+ #puts "*** result: #{Oj.dump(result, indent: 2)}"
24
+
25
+ assert_equal Oj.dump(result, mode: :rails), Oj.dump(result.to_hash)
26
+ end
27
+ end
@@ -0,0 +1,15 @@
1
+ #require 'active_support'
2
+ #require 'active_support/core_ext'
3
+ #require 'active_support/json'
4
+ require 'oj'
5
+
6
+ #Oj.optimize_rails
7
+ Oj.mimic_JSON
8
+
9
+ h = {:type=>:record, :name=>:group, :namespace=>"com.salsify.identity", :fields=>[{:name=>"id", :type=>{:name=>:salsify_uuid, :type=>:fixed, :namespace=>"com.salsify", :size=>38}}, {:name=>"type", :type=>"string", :default=>"groups"}, {:name=>"external_id", :type=>[:null, "string"], :default=>nil}, {:name=>"created_at", :type=>{:type=>"long", :logicalType=>"timestamp-micros"}}, {:name=>"updated_at", :type=>{:type=>"long", :logicalType=>"timestamp-micros"}}, {:name=>"name", :type=>"string"}, {:name=>"policy", :type=>[:null, {:type=>:record, :name=>:policy, :namespace=>"com.salsify.security", :fields=>[{:name=>"created_at", :type=>{:type=>"long", :logicalType=>"timestamp-micros"}}, {:name=>"updated_at", :type=>{:type=>"long", :logicalType=>"timestamp-micros"}}, {:name=>"id", :type=>"com.salsify.salsify_uuid"}, {:name=>"type", :type=>"string", :default=>"policies"}, {:name=>"external_id", :type=>[:null, "string"], :default=>nil}, {:name=>"name", :type=>"string"}, {:name=>"statements", :type=>{:type=>:array, :items=>{:type=>:record, :name=>:statement, :namespace=>"com.salsify.security", :fields=>[{:name=>"created_at", :type=>{:type=>"long", :logicalType=>"timestamp-micros"}}, {:name=>"updated_at", :type=>{:type=>"long", :logicalType=>"timestamp-micros"}}, {:name=>"id", :type=>"com.salsify.salsify_uuid"}, {:name=>"type", :type=>"string", :default=>"statements"}, {:name=>"external_id", :type=>[:null, "string"], :default=>nil}, {:name=>"action", :type=>{:name=>"__statement_action_enum", :type=>:enum, :namespace=>"com.salsify.security", :symbols=>[:manage, :read]}}, {:name=>"resource", :type=>{:name=>"__statement_resource_enum", :type=>:enum, :namespace=>"com.salsify.security", :symbols=>[:product, :digital_asset]}}, {:name=>"conditions", :type=>{:type=>:array, :items=>{:type=>:record, :name=>:condition, :namespace=>"com.salsify.security", :fields=>[{:name=>"created_at", :type=>{:type=>"long", :logicalType=>"timestamp-micros"}}, {:name=>"updated_at", :type=>{:type=>"long", :logicalType=>"timestamp-micros"}}, {:name=>"id", :type=>"com.salsify.salsify_uuid"}, {:name=>"type", :type=>"string", :default=>"conditions"}, {:name=>"external_id", :type=>[:null, "string"], :default=>nil}, {:name=>"operator", :type=>{:name=>"__condition_operator_enum", :type=>:enum, :namespace=>"com.salsify.security", :symbols=>[:equals]}}, {:name=>"attribute_type", :type=>{:name=>"__condition_attribute_type_enum", :type=>:enum, :namespace=>"com.salsify.security", :symbols=>[:resource]}}, {:name=>"value", :type=>"string"}, {:name=>"attribute", :type=>[:null, {:type=>:record, :name=>:reference, :namespace=>"com.salsify", :fields=>[{:name=>"id", :type=>"com.salsify.salsify_uuid"}, {:name=>"type", :type=>"string", :doc=>"snake_case, plural name for the resource type"}, {:name=>"external_id", :type=>[:null, "string"], :default=>nil}]}], :default=>nil}, {:name=>"broken", :type=>[:null, "boolean"], :default=>nil}]}}}]}}}]}], :default=>nil}]}
10
+
11
+ #Oj.dump(h)
12
+ puts JSON.pretty_generate(h)
13
+ #puts JSON.fast_generate(h)
14
+ #puts JSON.generate(h)
15
+
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.5.1
4
+ version: 3.6.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: 2018-04-13 00:00:00.000000000 Z
11
+ date: 2018-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -166,6 +166,7 @@ files:
166
166
  - test/_test_active.rb
167
167
  - test/_test_active_mimic.rb
168
168
  - test/_test_mimic_rails.rb
169
+ - test/activerecord/result_test.rb
169
170
  - test/activesupport4/decoding_test.rb
170
171
  - test/activesupport4/encoding_test.rb
171
172
  - test/activesupport4/test_helper.rb
@@ -174,6 +175,7 @@ files:
174
175
  - test/activesupport5/encoding_test_cases.rb
175
176
  - test/activesupport5/test_helper.rb
176
177
  - test/activesupport5/time_zone_test_helpers.rb
178
+ - test/big.rb
177
179
  - test/files.rb
178
180
  - test/foo.rb
179
181
  - test/helper.rb
@@ -302,6 +304,7 @@ test_files:
302
304
  - test/test_object.rb
303
305
  - test/perf_wab.rb
304
306
  - test/tests_mimic.rb
307
+ - test/activerecord/result_test.rb
305
308
  - test/perf_saj.rb
306
309
  - test/tests_mimic_addition.rb
307
310
  - test/test_saj.rb
@@ -314,6 +317,7 @@ test_files:
314
317
  - test/_test_active.rb
315
318
  - test/test_compat.rb
316
319
  - test/sample_json.rb
320
+ - test/big.rb
317
321
  - test/json_gem/test_helper.rb
318
322
  - test/json_gem/json_generic_object_test.rb
319
323
  - test/json_gem/json_common_interface_test.rb