Method: Oj::Rails.set_decoder
- Defined in:
- ext/oj/rails.c
permalink .set_decoder ⇒ Object
Sets the JSON.parse function to be the Oj::parse function which is json gem compatible.
1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 |
# File 'ext/oj/rails.c', line 1088
static VALUE rails_set_decoder(VALUE self) {
VALUE json;
VALUE json_error;
VALUE verbose;
if (rb_const_defined_at(rb_cObject, rb_intern("JSON"))) {
json = rb_const_get_at(rb_cObject, rb_intern("JSON"));
} else {
json = rb_define_module("JSON");
}
if (rb_const_defined_at(json, rb_intern("JSONError"))) {
json_error = rb_const_get(json, rb_intern("JSONError"));
} else {
json_error = rb_define_class_under(json, "JSONError", rb_eStandardError);
}
rb_global_variable(&oj_json_parser_error_class);
if (rb_const_defined_at(json, rb_intern("ParserError"))) {
oj_json_parser_error_class = rb_const_get(json, rb_intern("ParserError"));
} else {
oj_json_parser_error_class = rb_define_class_under(json, "ParserError", json_error);
}
// rb_undef_method doesn't work for modules or maybe sometimes
// doesn't. Anyway setting verbose should hide the warning.
verbose = rb_gv_get("$VERBOSE");
rb_gv_set("$VERBOSE", Qfalse);
rb_undef_method(json, "parse");
rb_define_module_function(json, "parse", oj_mimic_parse, -1);
rb_gv_set("$VERBOSE", verbose);
return Qnil;
}
|