oj 3.13.23 → 3.16.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +86 -0
- data/README.md +2 -2
- data/ext/oj/buf.h +7 -6
- data/ext/oj/cache.c +29 -26
- data/ext/oj/cache.h +3 -2
- data/ext/oj/cache8.c +10 -9
- data/ext/oj/circarray.c +7 -5
- data/ext/oj/circarray.h +2 -2
- data/ext/oj/code.c +5 -12
- data/ext/oj/code.h +2 -2
- data/ext/oj/compat.c +20 -60
- data/ext/oj/custom.c +26 -59
- data/ext/oj/debug.c +3 -9
- data/ext/oj/dump.c +103 -53
- data/ext/oj/dump.h +1 -4
- data/ext/oj/dump_compat.c +557 -592
- data/ext/oj/dump_leaf.c +3 -5
- data/ext/oj/dump_object.c +42 -48
- data/ext/oj/dump_strict.c +10 -22
- data/ext/oj/encoder.c +1 -1
- data/ext/oj/err.c +2 -13
- data/ext/oj/err.h +9 -12
- data/ext/oj/extconf.rb +16 -7
- data/ext/oj/fast.c +63 -98
- data/ext/oj/intern.c +62 -47
- data/ext/oj/intern.h +3 -7
- data/ext/oj/mem.c +318 -0
- data/ext/oj/mem.h +53 -0
- data/ext/oj/mimic_json.c +54 -38
- data/ext/oj/object.c +33 -43
- data/ext/oj/odd.c +8 -6
- data/ext/oj/odd.h +4 -4
- data/ext/oj/oj.c +245 -216
- data/ext/oj/oj.h +83 -81
- data/ext/oj/parse.c +109 -153
- data/ext/oj/parse.h +21 -24
- data/ext/oj/parser.c +80 -67
- data/ext/oj/parser.h +9 -8
- data/ext/oj/rails.c +71 -94
- data/ext/oj/reader.c +9 -14
- data/ext/oj/reader.h +4 -2
- data/ext/oj/resolve.c +3 -4
- data/ext/oj/rxclass.c +6 -5
- data/ext/oj/rxclass.h +1 -1
- data/ext/oj/saj.c +13 -15
- data/ext/oj/saj2.c +37 -49
- data/ext/oj/saj2.h +1 -1
- data/ext/oj/scp.c +6 -20
- data/ext/oj/sparse.c +22 -70
- data/ext/oj/stream_writer.c +46 -48
- data/ext/oj/strict.c +22 -56
- data/ext/oj/string_writer.c +64 -40
- data/ext/oj/trace.h +31 -4
- data/ext/oj/usual.c +125 -114
- data/ext/oj/usual.h +7 -6
- data/ext/oj/util.h +1 -1
- data/ext/oj/val_stack.c +13 -2
- data/ext/oj/val_stack.h +8 -7
- data/ext/oj/wab.c +25 -57
- data/lib/oj/active_support_helper.rb +1 -3
- data/lib/oj/bag.rb +7 -1
- data/lib/oj/easy_hash.rb +4 -5
- data/lib/oj/error.rb +0 -1
- data/lib/oj/json.rb +162 -150
- data/lib/oj/mimic.rb +7 -7
- data/lib/oj/schandler.rb +5 -4
- data/lib/oj/state.rb +8 -5
- data/lib/oj/version.rb +1 -2
- data/lib/oj.rb +2 -0
- data/pages/InstallOptions.md +20 -0
- data/pages/Options.md +4 -0
- metadata +46 -121
- data/test/_test_active.rb +0 -76
- data/test/_test_active_mimic.rb +0 -96
- data/test/_test_mimic_rails.rb +0 -126
- data/test/activerecord/result_test.rb +0 -32
- data/test/activesupport4/decoding_test.rb +0 -108
- data/test/activesupport4/encoding_test.rb +0 -531
- data/test/activesupport4/test_helper.rb +0 -41
- data/test/activesupport5/abstract_unit.rb +0 -45
- data/test/activesupport5/decoding_test.rb +0 -133
- data/test/activesupport5/encoding_test.rb +0 -500
- data/test/activesupport5/encoding_test_cases.rb +0 -98
- data/test/activesupport5/test_helper.rb +0 -72
- data/test/activesupport5/time_zone_test_helpers.rb +0 -39
- data/test/activesupport6/abstract_unit.rb +0 -44
- data/test/activesupport6/decoding_test.rb +0 -133
- data/test/activesupport6/encoding_test.rb +0 -507
- data/test/activesupport6/encoding_test_cases.rb +0 -98
- data/test/activesupport6/test_common.rb +0 -17
- data/test/activesupport6/test_helper.rb +0 -163
- data/test/activesupport6/time_zone_test_helpers.rb +0 -39
- data/test/activesupport7/abstract_unit.rb +0 -49
- data/test/activesupport7/decoding_test.rb +0 -125
- data/test/activesupport7/encoding_test.rb +0 -486
- data/test/activesupport7/encoding_test_cases.rb +0 -104
- data/test/activesupport7/time_zone_test_helpers.rb +0 -47
- data/test/bar.rb +0 -11
- data/test/baz.rb +0 -16
- data/test/bug.rb +0 -16
- data/test/files.rb +0 -29
- data/test/foo.rb +0 -77
- data/test/helper.rb +0 -42
- data/test/isolated/shared.rb +0 -308
- data/test/isolated/test_mimic_after.rb +0 -13
- data/test/isolated/test_mimic_alone.rb +0 -12
- data/test/isolated/test_mimic_as_json.rb +0 -45
- data/test/isolated/test_mimic_before.rb +0 -13
- data/test/isolated/test_mimic_define.rb +0 -28
- data/test/isolated/test_mimic_rails_after.rb +0 -22
- data/test/isolated/test_mimic_rails_before.rb +0 -21
- data/test/isolated/test_mimic_redefine.rb +0 -15
- data/test/json_gem/json_addition_test.rb +0 -216
- data/test/json_gem/json_common_interface_test.rb +0 -153
- data/test/json_gem/json_encoding_test.rb +0 -107
- data/test/json_gem/json_ext_parser_test.rb +0 -20
- data/test/json_gem/json_fixtures_test.rb +0 -35
- data/test/json_gem/json_generator_test.rb +0 -396
- data/test/json_gem/json_generic_object_test.rb +0 -90
- data/test/json_gem/json_parser_test.rb +0 -477
- data/test/json_gem/json_string_matching_test.rb +0 -42
- data/test/json_gem/test_helper.rb +0 -30
- data/test/mem.rb +0 -33
- data/test/perf.rb +0 -107
- data/test/perf_compat.rb +0 -130
- data/test/perf_dump.rb +0 -50
- data/test/perf_fast.rb +0 -164
- data/test/perf_file.rb +0 -64
- data/test/perf_object.rb +0 -138
- data/test/perf_once.rb +0 -58
- data/test/perf_parser.rb +0 -189
- data/test/perf_saj.rb +0 -109
- data/test/perf_scp.rb +0 -152
- data/test/perf_simple.rb +0 -287
- data/test/perf_strict.rb +0 -139
- data/test/perf_wab.rb +0 -131
- data/test/prec.rb +0 -23
- data/test/sample/change.rb +0 -14
- data/test/sample/dir.rb +0 -19
- data/test/sample/doc.rb +0 -36
- data/test/sample/file.rb +0 -48
- data/test/sample/group.rb +0 -16
- data/test/sample/hasprops.rb +0 -16
- data/test/sample/layer.rb +0 -12
- data/test/sample/line.rb +0 -20
- data/test/sample/oval.rb +0 -10
- data/test/sample/rect.rb +0 -10
- data/test/sample/shape.rb +0 -35
- data/test/sample/text.rb +0 -20
- data/test/sample.rb +0 -54
- data/test/sample_json.rb +0 -37
- data/test/test_compat.rb +0 -540
- data/test/test_custom.rb +0 -544
- data/test/test_debian.rb +0 -53
- data/test/test_fast.rb +0 -530
- data/test/test_file.rb +0 -255
- data/test/test_gc.rb +0 -60
- data/test/test_generate.rb +0 -21
- data/test/test_hash.rb +0 -39
- data/test/test_integer_range.rb +0 -72
- data/test/test_null.rb +0 -376
- data/test/test_object.rb +0 -1025
- data/test/test_parser.rb +0 -11
- data/test/test_parser_debug.rb +0 -27
- data/test/test_parser_saj.rb +0 -335
- data/test/test_parser_usual.rb +0 -217
- data/test/test_rails.rb +0 -35
- data/test/test_saj.rb +0 -186
- data/test/test_scp.rb +0 -431
- data/test/test_strict.rb +0 -435
- data/test/test_various.rb +0 -752
- data/test/test_wab.rb +0 -309
- data/test/test_writer.rb +0 -380
- data/test/tests.rb +0 -33
- data/test/tests_mimic.rb +0 -23
- data/test/tests_mimic_addition.rb +0 -16
- data/test/zoo.rb +0 -13
data/ext/oj/val_stack.h
CHANGED
@@ -6,6 +6,7 @@
|
|
6
6
|
|
7
7
|
#include <stdint.h>
|
8
8
|
|
9
|
+
#include "mem.h"
|
9
10
|
#include "odd.h"
|
10
11
|
#include "ruby.h"
|
11
12
|
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
@@ -28,10 +29,10 @@ typedef enum {
|
|
28
29
|
|
29
30
|
typedef struct _val {
|
30
31
|
volatile VALUE val;
|
31
|
-
const char
|
32
|
+
const char *key;
|
32
33
|
char karray[32];
|
33
34
|
volatile VALUE key_val;
|
34
|
-
const char
|
35
|
+
const char *classname;
|
35
36
|
VALUE clas;
|
36
37
|
OddArgs odd_args;
|
37
38
|
uint16_t klen;
|
@@ -39,7 +40,7 @@ typedef struct _val {
|
|
39
40
|
char next; // ValNext
|
40
41
|
char k1; // first original character in the key
|
41
42
|
char kalloc;
|
42
|
-
} *
|
43
|
+
} *Val;
|
43
44
|
|
44
45
|
typedef struct _valStack {
|
45
46
|
struct _val base[STACK_INC];
|
@@ -52,7 +53,7 @@ typedef struct _valStack {
|
|
52
53
|
VALUE mutex;
|
53
54
|
#endif
|
54
55
|
|
55
|
-
} *
|
56
|
+
} *ValStack;
|
56
57
|
|
57
58
|
extern VALUE oj_stack_init(ValStack stack);
|
58
59
|
|
@@ -62,7 +63,7 @@ inline static int stack_empty(ValStack stack) {
|
|
62
63
|
|
63
64
|
inline static void stack_cleanup(ValStack stack) {
|
64
65
|
if (stack->base != stack->head) {
|
65
|
-
|
66
|
+
OJ_R_FREE(stack->head);
|
66
67
|
stack->head = NULL;
|
67
68
|
}
|
68
69
|
}
|
@@ -76,10 +77,10 @@ inline static void stack_push(ValStack stack, VALUE val, ValNext next) {
|
|
76
77
|
// A realloc can trigger a GC so make sure it happens outside the lock
|
77
78
|
// but lock before changing pointers.
|
78
79
|
if (stack->base == stack->head) {
|
79
|
-
head =
|
80
|
+
head = OJ_R_ALLOC_N(struct _val, len + STACK_INC);
|
80
81
|
memcpy(head, stack->base, sizeof(struct _val) * len);
|
81
82
|
} else {
|
82
|
-
|
83
|
+
OJ_R_REALLOC_N(head, struct _val, len + STACK_INC);
|
83
84
|
}
|
84
85
|
#ifdef HAVE_PTHREAD_MUTEX_INIT
|
85
86
|
pthread_mutex_lock(&stack->mutex);
|
data/ext/oj/wab.c
CHANGED
@@ -76,15 +76,13 @@ static VALUE resolve_uri_http_class(void) {
|
|
76
76
|
}
|
77
77
|
|
78
78
|
static void raise_wab(VALUE obj) {
|
79
|
-
rb_raise(rb_eTypeError,
|
80
|
-
"Failed to dump %s Object to JSON in wab mode.\n",
|
81
|
-
rb_class2name(rb_obj_class(obj)));
|
79
|
+
rb_raise(rb_eTypeError, "Failed to dump %s Object to JSON in wab mode.\n", rb_class2name(rb_obj_class(obj)));
|
82
80
|
}
|
83
81
|
|
84
82
|
// Removed dependencies on math due to problems with CentOS 5.4.
|
85
83
|
static void dump_float(VALUE obj, int depth, Out out, bool as_ok) {
|
86
84
|
char buf[64];
|
87
|
-
char
|
85
|
+
char *b;
|
88
86
|
double d = rb_num2dbl(obj);
|
89
87
|
int cnt = 0;
|
90
88
|
|
@@ -226,13 +224,13 @@ static void dump_obj(VALUE obj, int depth, Out out, bool as_ok) {
|
|
226
224
|
if (rb_cTime == clas) {
|
227
225
|
dump_time(obj, out);
|
228
226
|
} else if (oj_bigdecimal_class == clas) {
|
229
|
-
volatile VALUE rstr =
|
227
|
+
volatile VALUE rstr = oj_safe_string_convert(obj);
|
230
228
|
|
231
229
|
oj_dump_raw(RSTRING_PTR(rstr), (int)RSTRING_LEN(rstr), out);
|
232
230
|
} else if (resolve_wab_uuid_class() == clas) {
|
233
|
-
oj_dump_str(
|
231
|
+
oj_dump_str(oj_safe_string_convert(obj), depth, out, false);
|
234
232
|
} else if (resolve_uri_http_class() == clas) {
|
235
|
-
oj_dump_str(
|
233
|
+
oj_dump_str(oj_safe_string_convert(obj), depth, out, false);
|
236
234
|
} else {
|
237
235
|
raise_wab(obj);
|
238
236
|
}
|
@@ -266,9 +264,7 @@ static DumpFunc wab_funcs[] = {
|
|
266
264
|
void oj_dump_wab_val(VALUE obj, int depth, Out out) {
|
267
265
|
int type = rb_type(obj);
|
268
266
|
|
269
|
-
|
270
|
-
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceIn);
|
271
|
-
}
|
267
|
+
TRACE(out->opts->trace, "dump", obj, depth, TraceIn);
|
272
268
|
if (MAX_DEPTH < depth) {
|
273
269
|
rb_raise(rb_eNoMemError, "Too deeply nested.\n");
|
274
270
|
}
|
@@ -277,9 +273,7 @@ void oj_dump_wab_val(VALUE obj, int depth, Out out) {
|
|
277
273
|
|
278
274
|
if (NULL != f) {
|
279
275
|
f(obj, depth, out, false);
|
280
|
-
|
281
|
-
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
|
282
|
-
}
|
276
|
+
TRACE(out->opts->trace, "dump", obj, depth, TraceOut);
|
283
277
|
return;
|
284
278
|
}
|
285
279
|
}
|
@@ -303,7 +297,7 @@ static VALUE calc_hash_key(ParseInfo pi, Val parent) {
|
|
303
297
|
#if HAVE_RB_ENC_INTERNED_STR
|
304
298
|
rkey = rb_enc_interned_str(parent->key, parent->klen, oj_utf8_encoding);
|
305
299
|
#else
|
306
|
-
|
300
|
+
rkey = rb_utf8_str_new(parent->key, parent->klen);
|
307
301
|
rkey = rb_str_intern(rkey);
|
308
302
|
OBJ_FREEZE(rkey);
|
309
303
|
#endif
|
@@ -312,15 +306,11 @@ static VALUE calc_hash_key(ParseInfo pi, Val parent) {
|
|
312
306
|
}
|
313
307
|
|
314
308
|
static void hash_end(ParseInfo pi) {
|
315
|
-
|
316
|
-
oj_trace_parse_hash_end(pi, __FILE__, __LINE__);
|
317
|
-
}
|
309
|
+
TRACE_PARSE_HASH_END(pi->options.trace, pi);
|
318
310
|
}
|
319
311
|
|
320
312
|
static void array_end(ParseInfo pi) {
|
321
|
-
|
322
|
-
oj_trace_parse_array_end(pi, __FILE__, __LINE__);
|
323
|
-
}
|
313
|
+
TRACE_PARSE_ARRAY_END(pi->options.trace, pi);
|
324
314
|
}
|
325
315
|
|
326
316
|
static VALUE noop_hash_key(ParseInfo pi, const char *key, size_t klen) {
|
@@ -328,9 +318,7 @@ static VALUE noop_hash_key(ParseInfo pi, const char *key, size_t klen) {
|
|
328
318
|
}
|
329
319
|
|
330
320
|
static void add_value(ParseInfo pi, VALUE val) {
|
331
|
-
|
332
|
-
oj_trace_parse_call("add_value", pi, __FILE__, __LINE__, val);
|
333
|
-
}
|
321
|
+
TRACE_PARSE_CALL(pi->options.trace, "add_value", pi, val);
|
334
322
|
pi->stack.head->val = val;
|
335
323
|
}
|
336
324
|
|
@@ -454,14 +442,14 @@ static VALUE protect_uri(VALUE rstr) {
|
|
454
442
|
static VALUE cstr_to_rstr(ParseInfo pi, const char *str, size_t len) {
|
455
443
|
volatile VALUE v = Qnil;
|
456
444
|
|
457
|
-
if (30 == len && '-' == str[4] && '-' == str[7] && 'T' == str[10] && ':' == str[13] &&
|
458
|
-
'
|
445
|
+
if (30 == len && '-' == str[4] && '-' == str[7] && 'T' == str[10] && ':' == str[13] && ':' == str[16] &&
|
446
|
+
'.' == str[19] && 'Z' == str[29]) {
|
459
447
|
if (Qnil != (v = time_parse(str, (int)len))) {
|
460
448
|
return v;
|
461
449
|
}
|
462
450
|
}
|
463
|
-
if (36 == len && '-' == str[8] && '-' == str[13] && '-' == str[18] && '-' == str[23] &&
|
464
|
-
|
451
|
+
if (36 == len && '-' == str[8] && '-' == str[13] && '-' == str[18] && '-' == str[23] && uuid_check(str, (int)len) &&
|
452
|
+
Qnil != resolve_wab_uuid_class()) {
|
465
453
|
return rb_funcall(wab_uuid_clas, oj_new_id, 1, rb_str_new(str, len));
|
466
454
|
}
|
467
455
|
if (7 < len && 0 == strncasecmp("http://", str, 7)) {
|
@@ -478,9 +466,7 @@ static VALUE cstr_to_rstr(ParseInfo pi, const char *str, size_t len) {
|
|
478
466
|
|
479
467
|
static void add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
480
468
|
pi->stack.head->val = cstr_to_rstr(pi, str, len);
|
481
|
-
|
482
|
-
oj_trace_parse_call("add_string", pi, __FILE__, __LINE__, pi->stack.head->val);
|
483
|
-
}
|
469
|
+
TRACE_PARSE_CALL(pi->options.trace, "add_string", pi, pi->stack.head->val);
|
484
470
|
}
|
485
471
|
|
486
472
|
static void add_num(ParseInfo pi, NumInfo ni) {
|
@@ -488,15 +474,11 @@ static void add_num(ParseInfo pi, NumInfo ni) {
|
|
488
474
|
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not a number or other value");
|
489
475
|
}
|
490
476
|
pi->stack.head->val = oj_num_as_value(ni);
|
491
|
-
|
492
|
-
oj_trace_parse_call("add_number", pi, __FILE__, __LINE__, pi->stack.head->val);
|
493
|
-
}
|
477
|
+
TRACE_PARSE_CALL(pi->options.trace, "add_number", pi, pi->stack.head->val);
|
494
478
|
}
|
495
479
|
|
496
480
|
static VALUE start_hash(ParseInfo pi) {
|
497
|
-
|
498
|
-
oj_trace_parse_in("start_hash", pi, __FILE__, __LINE__);
|
499
|
-
}
|
481
|
+
TRACE_PARSE_IN(pi->options.trace, "start_hash", pi);
|
500
482
|
if (Qnil != pi->options.hash_class) {
|
501
483
|
return rb_class_new_instance(0, NULL, pi->options.hash_class);
|
502
484
|
}
|
@@ -507,9 +489,7 @@ static void hash_set_cstr(ParseInfo pi, Val parent, const char *str, size_t len,
|
|
507
489
|
volatile VALUE rval = cstr_to_rstr(pi, str, len);
|
508
490
|
|
509
491
|
rb_hash_aset(stack_peek(&pi->stack)->val, calc_hash_key(pi, parent), rval);
|
510
|
-
|
511
|
-
oj_trace_parse_call("set_string", pi, __FILE__, __LINE__, rval);
|
512
|
-
}
|
492
|
+
TRACE_PARSE_CALL(pi->options.trace, "set_string", pi, rval);
|
513
493
|
}
|
514
494
|
|
515
495
|
static void hash_set_num(ParseInfo pi, Val parent, NumInfo ni) {
|
@@ -520,22 +500,16 @@ static void hash_set_num(ParseInfo pi, Val parent, NumInfo ni) {
|
|
520
500
|
}
|
521
501
|
rval = oj_num_as_value(ni);
|
522
502
|
rb_hash_aset(stack_peek(&pi->stack)->val, calc_hash_key(pi, parent), rval);
|
523
|
-
|
524
|
-
oj_trace_parse_call("set_number", pi, __FILE__, __LINE__, rval);
|
525
|
-
}
|
503
|
+
TRACE_PARSE_CALL(pi->options.trace, "set_number", pi, rval);
|
526
504
|
}
|
527
505
|
|
528
506
|
static void hash_set_value(ParseInfo pi, Val parent, VALUE value) {
|
529
507
|
rb_hash_aset(stack_peek(&pi->stack)->val, calc_hash_key(pi, parent), value);
|
530
|
-
|
531
|
-
oj_trace_parse_call("set_value", pi, __FILE__, __LINE__, value);
|
532
|
-
}
|
508
|
+
TRACE_PARSE_CALL(pi->options.trace, "set_value", pi, value);
|
533
509
|
}
|
534
510
|
|
535
511
|
static VALUE start_array(ParseInfo pi) {
|
536
|
-
|
537
|
-
oj_trace_parse_in("start_array", pi, __FILE__, __LINE__);
|
538
|
-
}
|
512
|
+
TRACE_PARSE_IN(pi->options.trace, "start_array", pi);
|
539
513
|
return rb_ary_new();
|
540
514
|
}
|
541
515
|
|
@@ -543,9 +517,7 @@ static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const c
|
|
543
517
|
volatile VALUE rval = cstr_to_rstr(pi, str, len);
|
544
518
|
|
545
519
|
rb_ary_push(stack_peek(&pi->stack)->val, rval);
|
546
|
-
|
547
|
-
oj_trace_parse_call("set_value", pi, __FILE__, __LINE__, rval);
|
548
|
-
}
|
520
|
+
TRACE_PARSE_CALL(pi->options.trace, "set_value", pi, rval);
|
549
521
|
}
|
550
522
|
|
551
523
|
static void array_append_num(ParseInfo pi, NumInfo ni) {
|
@@ -556,16 +528,12 @@ static void array_append_num(ParseInfo pi, NumInfo ni) {
|
|
556
528
|
}
|
557
529
|
rval = oj_num_as_value(ni);
|
558
530
|
rb_ary_push(stack_peek(&pi->stack)->val, rval);
|
559
|
-
|
560
|
-
oj_trace_parse_call("append_number", pi, __FILE__, __LINE__, rval);
|
561
|
-
}
|
531
|
+
TRACE_PARSE_CALL(pi->options.trace, "append_number", pi, rval);
|
562
532
|
}
|
563
533
|
|
564
534
|
static void array_append_value(ParseInfo pi, VALUE value) {
|
565
535
|
rb_ary_push(stack_peek(&pi->stack)->val, value);
|
566
|
-
|
567
|
-
oj_trace_parse_call("append_value", pi, __FILE__, __LINE__, value);
|
568
|
-
}
|
536
|
+
TRACE_PARSE_CALL(pi->options.trace, "append_value", pi, value);
|
569
537
|
}
|
570
538
|
|
571
539
|
void oj_set_wab_callbacks(ParseInfo pi) {
|
@@ -1,16 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
3
|
require 'active_support/time'
|
3
4
|
|
4
5
|
module Oj
|
5
|
-
|
6
6
|
# Exists only to handle the ActiveSupport::TimeWithZone.
|
7
7
|
class ActiveSupportHelper
|
8
|
-
|
9
8
|
def self.createTimeWithZone(utc, zone)
|
10
9
|
ActiveSupport::TimeWithZone.new(utc - utc.gmt_offset, ActiveSupport::TimeZone[zone])
|
11
10
|
end
|
12
11
|
end
|
13
|
-
|
14
12
|
end
|
15
13
|
|
16
14
|
Oj.register_odd(ActiveSupport::TimeWithZone, Oj::ActiveSupportHelper, :createTimeWithZone, :utc, 'time_zone.name')
|
data/lib/oj/bag.rb
CHANGED
@@ -15,7 +15,7 @@ module Oj
|
|
15
15
|
# @example Oj::Bag.new(:@x => 42, :@y => 57)
|
16
16
|
# @param [Hash] args instance variable symbols and their values
|
17
17
|
def initialize(args = {})
|
18
|
-
args.each do |k,v|
|
18
|
+
args.each do |k, v|
|
19
19
|
self.instance_variable_set(k, v)
|
20
20
|
end
|
21
21
|
end
|
@@ -26,6 +26,7 @@ module Oj
|
|
26
26
|
# variable reader, otherwise false.
|
27
27
|
def respond_to?(m)
|
28
28
|
return true if super
|
29
|
+
|
29
30
|
instance_variables.include?(:"@#{m}")
|
30
31
|
end
|
31
32
|
|
@@ -37,8 +38,10 @@ module Oj
|
|
37
38
|
# @raise [NoMethodError] if the instance variable is not defined.
|
38
39
|
def method_missing(m, *args, &block)
|
39
40
|
raise ArgumentError.new("wrong number of arguments (#{args.size} for 0) to method #{m}") unless args.nil? or args.empty?
|
41
|
+
|
40
42
|
at_m = :"@#{m}"
|
41
43
|
raise NoMethodError.new("undefined method #{m}", m) unless instance_variable_defined?(at_m)
|
44
|
+
|
42
45
|
instance_variable_get(at_m)
|
43
46
|
end
|
44
47
|
|
@@ -47,9 +50,11 @@ module Oj
|
|
47
50
|
# @return [Boolean] true if each variable and value are the same, otherwise false.
|
48
51
|
def eql?(other)
|
49
52
|
return false if (other.nil? or self.class != other.class)
|
53
|
+
|
50
54
|
ova = other.instance_variables
|
51
55
|
iv = instance_variables
|
52
56
|
return false if ova.size != iv.size
|
57
|
+
|
53
58
|
iv.all? { |vid| instance_variable_get(vid) != other.instance_variable_get(vid) }
|
54
59
|
end
|
55
60
|
alias == eql?
|
@@ -65,6 +70,7 @@ module Oj
|
|
65
70
|
classname = classname.to_s unless classname.is_a?(String)
|
66
71
|
tokens = classname.split('::').map(&:to_sym)
|
67
72
|
raise NameError.new("Invalid classname '#{classname}") if tokens.empty?
|
73
|
+
|
68
74
|
m = Object
|
69
75
|
tokens[0..-2].each do |sym|
|
70
76
|
if m.const_defined?(sym)
|
data/lib/oj/easy_hash.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
module Oj
|
3
2
|
|
4
3
|
# A Hash subclass that normalizes the hash keys to allow lookup by the
|
@@ -6,10 +5,6 @@ module Oj
|
|
6
5
|
# that match the keys.
|
7
6
|
class EasyHash < Hash
|
8
7
|
|
9
|
-
# Initializes the instance to an empty Hash.
|
10
|
-
def initialize()
|
11
|
-
end
|
12
|
-
|
13
8
|
# Replaces the Object.respond_to?() method.
|
14
9
|
# @param [Symbol] m method symbol
|
15
10
|
# @param [Boolean] include_all whether to include private and protected methods in the search
|
@@ -19,12 +14,14 @@ module Oj
|
|
19
14
|
return true if super
|
20
15
|
return true if has_key?(m)
|
21
16
|
return true if has_key?(m.to_s)
|
17
|
+
|
22
18
|
has_key?(m.to_sym)
|
23
19
|
end
|
24
20
|
|
25
21
|
def [](key)
|
26
22
|
return fetch(key, nil) if has_key?(key)
|
27
23
|
return fetch(key.to_s, nil) if has_key?(key.to_s)
|
24
|
+
|
28
25
|
fetch(key.to_sym, nil)
|
29
26
|
end
|
30
27
|
|
@@ -36,9 +33,11 @@ module Oj
|
|
36
33
|
def method_missing(m, *args, &block)
|
37
34
|
if m.to_s.end_with?('=')
|
38
35
|
raise ArgumentError.new("wrong number of arguments (#{args.size} for 1 with #{m}) to method #{m}") if args.nil? or 1 != args.length
|
36
|
+
|
39
37
|
m = m[0..-2]
|
40
38
|
return store(m.to_s, args[0]) if has_key?(m.to_s)
|
41
39
|
return store(m.to_sym, args[0]) if has_key?(m.to_sym)
|
40
|
+
|
42
41
|
return store(m, args[0])
|
43
42
|
else
|
44
43
|
raise ArgumentError.new("wrong number of arguments (#{args.size} for 0 with #{m}) to method #{m}") unless args.nil? or args.empty?
|
data/lib/oj/error.rb
CHANGED