Method: Oj::Parser#method_missing

Defined in:
ext/oj/parser.c

#method_missing(value) ⇒ Object

Methods not handled by the parser are passed to the delegate. The methods supported by delegate are:

  • :validate

    • no options

  • :saj

    • cache_keys is a flag indicating hash keys should be cached.

    • cache_strings is a positive integer less than 35. Strings shorter than that length are cached.

    • handler is the SAJ handler

  • :usual

    • cache_keys is a flag indicating hash keys should be cached.

    • cache_strings is a positive integer less than 35. Strings shorter than that length are cached.

    • cache_expunge dictates when the cache will be expunged where 0 never expunges, 1 expunges slowly, 2 expunges faster, and 3 or higher expunges agressively.

    • capacity is the capacity of the parser’s internal stack. The parser grows automatically but can be updated directly with this call.

    • create_id if non-nil is the key that is used to specify the type of object to create when parsing. Parsed JSON objects that include the specified element use the element value as the name of the class to create an object from instead of a Hash.

    • decimal is the approach to how decimals are parsed. If :auto then the decimals with significant digits are 16 or less are Floats and long ones are BigDecimal. :ruby uses a call to Ruby to convert a string to a Float. :float always generates a Float. :bigdecimal always results in a BigDecimal.

    • ignore_json_create is a flag that when set the class json_create method is ignored on parsing in favor of creating an instance and populating directly.

    • missing_class is an indicator that determines how unknown class names are handled. Valid values are :auto which creates any missing classes on parse, :ignore which ignores and continues as a Hash (default), and :raise which raises an exception if the class is not found.

    • omit_null is a flag that if true then null values in a map or object are omitted from the resulting Hash or Object.

    • symbol_keys is a flag that indicates Hash keys should be parsed to Symbols versus Strings.



1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
# File 'ext/oj/parser.c', line 1084

static VALUE parser_missing(int argc, VALUE *argv, VALUE self) {
    ojParser       p;
    const char    *key  = NULL;
    volatile VALUE rkey = *argv;
    volatile VALUE rv   = Qnil;

    TypedData_Get_Struct(self, struct _ojParser, &oj_parser_type, p);

#if HAVE_RB_EXT_RACTOR_SAFE
    // This doesn't seem to do anything.
    rb_ext_ractor_safe(true);
#endif
    switch (rb_type(rkey)) {
    case RUBY_T_SYMBOL:
        rkey = rb_sym2str(rkey);
        // fall through
    case RUBY_T_STRING: key = StringValuePtr(rkey); break;
    default: rb_raise(rb_eArgError, "option method must be a symbol or string");
    }
    if (1 < argc) {
        rv = argv[1];
    }
    return p->option(p, key, rv);
}