oj 3.6.7 → 3.6.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/oj/custom.c +61 -27
- data/ext/oj/rails.c +2 -2
- data/lib/oj/version.rb +1 -1
- data/test/test_custom.rb +51 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aba240d544c37d3f3c5e2a6c7fe51b29507ba354b76ede963bd868e620df4ece
|
4
|
+
data.tar.gz: 832dd821fa37c9ff2fd7b993c2529537a86b54ca2eded2a72f39ac8c6980bfd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e485a0613aa0306d2a5239fbccc510cfc67456760f6e01ad65c7075f2c42f0a2a6fd796dca4b35e8002a2ec7ee950801ae0ce2478ebae0e3e7715d8021eef4dc
|
7
|
+
data.tar.gz: fa9a0f9e185ae31e783515012f1b9e5c09bc4341e1cfe5f20f8341639d30fef5ae2d748b260fe12e3753eaf4d3e7260c5ee67d81a5706b2b950256065a5530a8
|
data/ext/oj/custom.c
CHANGED
@@ -79,15 +79,70 @@ complex_load(VALUE clas, VALUE args) {
|
|
79
79
|
return rb_complex_new(rb_hash_aref(args, rb_id2str(real_id)), rb_hash_aref(args, rb_id2str(imag_id)));
|
80
80
|
}
|
81
81
|
|
82
|
+
static void
|
83
|
+
time_dump(VALUE obj, int depth, Out out) {
|
84
|
+
if (Yes == out->opts->create_ok) {
|
85
|
+
struct _Attr attrs[] = {
|
86
|
+
{ "time", 4, Qundef, 0, Qundef },
|
87
|
+
{ NULL, 0, Qnil },
|
88
|
+
};
|
89
|
+
attrs->time = obj;
|
90
|
+
|
91
|
+
oj_code_attrs(obj, attrs, depth, out, true);
|
92
|
+
} else {
|
93
|
+
switch (out->opts->time_format) {
|
94
|
+
case RubyTime: oj_dump_ruby_time(obj, out); break;
|
95
|
+
case XmlTime: oj_dump_xml_time(obj, out); break;
|
96
|
+
case UnixZTime: oj_dump_time(obj, out, true); break;
|
97
|
+
case UnixTime:
|
98
|
+
default: oj_dump_time(obj, out, false); break;
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
82
103
|
static void
|
83
104
|
date_dump(VALUE obj, int depth, Out out) {
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
105
|
+
if (Yes == out->opts->create_ok) {
|
106
|
+
struct _Attr attrs[] = {
|
107
|
+
{ "s", 1, Qnil },
|
108
|
+
{ NULL, 0, Qnil },
|
109
|
+
};
|
110
|
+
attrs->value = rb_funcall(obj, rb_intern("iso8601"), 0);
|
89
111
|
|
90
|
-
|
112
|
+
oj_code_attrs(obj, attrs, depth, out, Yes == out->opts->create_ok);
|
113
|
+
} else {
|
114
|
+
volatile VALUE v;
|
115
|
+
volatile VALUE ov;
|
116
|
+
|
117
|
+
switch (out->opts->time_format) {
|
118
|
+
case RubyTime:
|
119
|
+
case XmlTime:
|
120
|
+
v = rb_funcall(obj, rb_intern("iso8601"), 0);
|
121
|
+
oj_dump_cstr(rb_string_value_ptr((VALUE*)&v), RSTRING_LEN(v), 0, 0, out);
|
122
|
+
break;
|
123
|
+
case UnixZTime:
|
124
|
+
v = rb_funcall(obj, rb_intern("to_time"), 0);
|
125
|
+
if (oj_date_class == rb_obj_class(obj)) {
|
126
|
+
ov = rb_funcall(v, rb_intern("utc_offset"), 0);
|
127
|
+
v = rb_funcall(v, rb_intern("utc"), 0);
|
128
|
+
v = rb_funcall(v, rb_intern("+"), 1, ov);
|
129
|
+
oj_dump_time(v, out, false);
|
130
|
+
} else {
|
131
|
+
oj_dump_time(v, out, true);
|
132
|
+
}
|
133
|
+
break;
|
134
|
+
case UnixTime:
|
135
|
+
default:
|
136
|
+
v = rb_funcall(obj, rb_intern("to_time"), 0);
|
137
|
+
if (oj_date_class == rb_obj_class(obj)) {
|
138
|
+
ov = rb_funcall(v, rb_intern("utc_offset"), 0);
|
139
|
+
v = rb_funcall(v, rb_intern("utc"), 0);
|
140
|
+
v = rb_funcall(v, rb_intern("+"), 1, ov);
|
141
|
+
}
|
142
|
+
oj_dump_time(v, out, false);
|
143
|
+
break;
|
144
|
+
}
|
145
|
+
}
|
91
146
|
}
|
92
147
|
|
93
148
|
static VALUE
|
@@ -200,27 +255,6 @@ regexp_load(VALUE clas, VALUE args) {
|
|
200
255
|
return Qnil;
|
201
256
|
}
|
202
257
|
|
203
|
-
static void
|
204
|
-
time_dump(VALUE obj, int depth, Out out) {
|
205
|
-
if (Yes == out->opts->create_ok) {
|
206
|
-
struct _Attr attrs[] = {
|
207
|
-
{ "time", 4, Qundef, 0, Qundef },
|
208
|
-
{ NULL, 0, Qnil },
|
209
|
-
};
|
210
|
-
attrs->time = obj;
|
211
|
-
|
212
|
-
oj_code_attrs(obj, attrs, depth, out, true);
|
213
|
-
} else {
|
214
|
-
switch (out->opts->time_format) {
|
215
|
-
case RubyTime: oj_dump_ruby_time(obj, out); break;
|
216
|
-
case XmlTime: oj_dump_xml_time(obj, out); break;
|
217
|
-
case UnixZTime: oj_dump_time(obj, out, true); break;
|
218
|
-
case UnixTime:
|
219
|
-
default: oj_dump_time(obj, out, false); break;
|
220
|
-
}
|
221
|
-
}
|
222
|
-
}
|
223
|
-
|
224
258
|
static VALUE
|
225
259
|
time_load(VALUE clas, VALUE args) {
|
226
260
|
// Value should have already been replaced in one of the hash_set_xxx
|
data/ext/oj/rails.c
CHANGED
@@ -451,7 +451,7 @@ dump_activerecord_result(VALUE obj, int depth, Out out, bool as_ok) {
|
|
451
451
|
out->argc = 0;
|
452
452
|
cols = columns_array(rb_ivar_get(obj, columns_id), &ccnt);
|
453
453
|
rows = rb_ivar_get(obj, rows_id);
|
454
|
-
rcnt = RARRAY_LEN(rows);
|
454
|
+
rcnt = (int)RARRAY_LEN(rows);
|
455
455
|
assure_size(out, 2);
|
456
456
|
*out->cur++ = '[';
|
457
457
|
if (out->opts->dump_opts.use) {
|
@@ -828,7 +828,7 @@ rails_mimic_json(VALUE self) {
|
|
828
828
|
json = rb_define_module("JSON");
|
829
829
|
}
|
830
830
|
oj_mimic_json_methods(json);
|
831
|
-
oj_default_options.mode = RailsMode;
|
831
|
+
//oj_default_options.mode = RailsMode;
|
832
832
|
|
833
833
|
return Qnil;
|
834
834
|
}
|
data/lib/oj/version.rb
CHANGED
data/test/test_custom.rb
CHANGED
@@ -300,11 +300,62 @@ class CustomJuice < Minitest::Test
|
|
300
300
|
dump_and_load(obj, false, :create_id => "^o", :create_additions => true)
|
301
301
|
end
|
302
302
|
|
303
|
+
def test_date_unix
|
304
|
+
obj = Date.new(2017, 1, 5)
|
305
|
+
json = Oj.dump(obj, :indent => 2, time_format: :unix)
|
306
|
+
assert_equal('1483574400.000000000', json)
|
307
|
+
end
|
308
|
+
|
309
|
+
def test_date_unix_zone
|
310
|
+
obj = Date.new(2017, 1, 5)
|
311
|
+
json = Oj.dump(obj, :indent => 2, time_format: :unix_zone)
|
312
|
+
assert_equal('1483574400.000000000', json)
|
313
|
+
end
|
314
|
+
|
315
|
+
def test_date_ruby
|
316
|
+
obj = Date.new(2017, 1, 5)
|
317
|
+
json = Oj.dump(obj, :indent => 2, time_format: :ruby)
|
318
|
+
assert_equal('"2017-01-05"', json)
|
319
|
+
end
|
320
|
+
|
321
|
+
def test_date_xmlschema
|
322
|
+
obj = Date.new(2017, 1, 5)
|
323
|
+
json = Oj.dump(obj, :indent => 2, time_format: :xmlschema)
|
324
|
+
assert_equal('"2017-01-05"', json)
|
325
|
+
end
|
326
|
+
|
303
327
|
def test_datetime
|
304
328
|
obj = DateTime.new(2017, 1, 5, 10, 20, 30)
|
305
329
|
dump_and_load(obj, false, :create_id => "^o", :create_additions => true)
|
306
330
|
end
|
307
331
|
|
332
|
+
def test_datetime_unix
|
333
|
+
obj = DateTime.new(2017, 1, 5, 10, 20, 30, '-0500')
|
334
|
+
json = Oj.dump(obj, :indent => 2, time_format: :unix)
|
335
|
+
assert_equal('1483629630.000000000', json)
|
336
|
+
end
|
337
|
+
|
338
|
+
def test_datetime_unix_zone
|
339
|
+
# older versions seems to have issues getting the utc offset.
|
340
|
+
if '2.4' <= RUBY_VERSION
|
341
|
+
obj = DateTime.new(2017, 1, 5, 10, 20, 30, '-0500')
|
342
|
+
json = Oj.dump(obj, :indent => 2, time_format: :unix_zone)
|
343
|
+
assert_equal('1483629630.000000000e-18000', json)
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
def test_datetime_ruby
|
348
|
+
obj = DateTime.new(2017, 1, 5, 10, 20, 30, '-0500')
|
349
|
+
json = Oj.dump(obj, :indent => 2, time_format: :ruby)
|
350
|
+
assert_equal('"2017-01-05T10:20:30-05:00"', json)
|
351
|
+
end
|
352
|
+
|
353
|
+
def test_datetime_xmlschema
|
354
|
+
obj = DateTime.new(2017, 1, 5, 10, 20, 30, '-0500')
|
355
|
+
json = Oj.dump(obj, :indent => 2, time_format: :xmlschema)
|
356
|
+
assert_equal('"2017-01-05T10:20:30-05:00"', json)
|
357
|
+
end
|
358
|
+
|
308
359
|
def test_regexp
|
309
360
|
# this notation must be used to get an == match later
|
310
361
|
obj = /(?ix-m:^yes$)/
|
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.6.
|
4
|
+
version: 3.6.8
|
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-08
|
11
|
+
date: 2018-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|