Class: Oj::Rails::Encoder
- Inherits:
-
Object
- Object
- Oj::Rails::Encoder
- Defined in:
- ext/oj/rails.c,
ext/oj/rails.c
Overview
The Oj ActiveSupport compliant encoder.
Class Method Summary collapse
-
.new(options = nil) ⇒ Object
Creates a new Encoder.
Instance Method Summary collapse
-
#deoptimize(*classes) ⇒ Object
Turn off Oj rails optimization on the specified classes.
-
#encode(obj) ⇒ Object
-
obj [Object] object to encode.
-
-
#optimize(*args) ⇒ Object
Document-method optimize call-seq: optimize(*classes).
-
#optimized?(clas) ⇒ Boolean
-
clas [Class] Class to check.
-
Class Method Details
.new(options = nil) ⇒ Object
Creates a new Encoder.
-
options [Hash] formatting options
660 661 662 663 664 665 666 667 668 669 670 671 672 |
# File 'ext/oj/rails.c', line 660 static VALUE encoder_new(int argc, VALUE *argv, VALUE self) { Encoder e = OJ_R_ALLOC(struct _encoder); e->opts = ; e->arg = Qnil; copy_opts(&ropts, &e->ropts); if (1 <= argc && Qnil != *argv) { (*argv, &e->opts); e->arg = *argv; } return TypedData_Wrap_Struct(encoder_class, &oj_encoder_type, e); } |
Instance Method Details
#deoptimize(*classes) ⇒ Object
Turn off Oj rails optimization on the specified classes.
-
classes [Class] a list of classes to deoptimize
819 820 821 822 823 824 825 826 |
# File 'ext/oj/rails.c', line 819 static VALUE encoder_deoptimize(int argc, VALUE *argv, VALUE self) { Encoder e; TypedData_Get_Struct(self, struct _encoder, &oj_encoder_type, e); optimize(argc, argv, &e->ropts, false); return Qnil; } |
#encode(obj) ⇒ Object
-
obj [Object] object to encode
Returns encoded object as a JSON string.
958 959 960 961 962 963 964 965 966 967 968 |
# File 'ext/oj/rails.c', line 958 static VALUE encoder_encode(VALUE self, VALUE obj) { Encoder e; TypedData_Get_Struct(self, struct _encoder, &oj_encoder_type, e); if (Qnil != e->arg) { VALUE argv[1] = {e->arg}; return encode(obj, &e->ropts, &e->opts, 1, argv); } return encode(obj, &e->ropts, &e->opts, 0, NULL); } |
#optimize(*args) ⇒ Object
Document-method optimize call-seq: optimize(*classes)
Use Oj rails optimized routines to encode the specified classes. This ignores the as_json() method on the class and uses an internal encoding instead. Passing in no classes indicates all should use the optimized version of encoding for all previously optimized classes. Passing in the Object class set a global switch that will then use the optimized behavior for all classes.
-
classes [Class] a list of classes to optimize
762 763 764 765 766 767 768 769 |
# File 'ext/oj/rails.c', line 762 static VALUE encoder_optimize(int argc, VALUE *argv, VALUE self) { Encoder e; TypedData_Get_Struct(self, struct _encoder, &oj_encoder_type, e); optimize(argc, argv, &e->ropts, true); return Qnil; } |
#optimized?(clas) ⇒ Boolean
-
clas [Class] Class to check
849 850 851 852 853 854 855 856 857 858 859 860 |
# File 'ext/oj/rails.c', line 849 static VALUE encoder_optimized(VALUE self, VALUE clas) { Encoder e; ROpt ro; TypedData_Get_Struct(self, struct _encoder, &oj_encoder_type, e); ro = oj_rails_get_opt(&e->ropts, clas); if (NULL == ro) { return Qfalse; } return (ro->on) ? Qtrue : Qfalse; } |