Skip to content

Commit

Permalink
frame from rails results dump
Browse files Browse the repository at this point in the history
  • Loading branch information
ohler55 committed Apr 29, 2018
1 parent d5d4e31 commit a81efb8
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions ext/oj/rails.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,57 @@ dump_actioncontroller_parameters(VALUE obj, int depth, Out out, bool as_ok) {
dump_rails_val(rb_ivar_get(obj, parameters_id), depth, out, true);
}

static const char**
columns_array(VALUE rcols, int *ccnt) {
volatile VALUE v;
const char **cols;
int i;
int cnt = RARRAY_LEN(rcols);

*ccnt = cnt;
cols = ALLOC_N(const char*, cnt);
for (i = 0; i < cnt; i++) {
v = rb_ary_entry(rcols, i);
// TBD should this check the type?
cols[i] = StringValuePtr(v);
}
return cols;
}

static ID rows_id = 0;
static ID columns_id = 0;

static void
dump_activesupport_result(VALUE obj, int depth, Out out, bool as_ok) {
volatile VALUE rows;
const char **cols;
int ccnt = 0;
int i, rcnt;

if (0 == rows_id) {
rows_id = rb_intern("@rows");
columns_id = rb_intern("@columns");
}
out->argc = 0;
cols = columns_array(rb_ivar_get(obj, columns_id), &ccnt);
rows = rb_ivar_get(obj, rows_id);
rcnt = RARRAY_LEN(rows);
for (i = 0; i < rcnt; i++) {
// TBD similar to dump_array
// call func to dump_row
// dump_rails_val(rb_ivar_get(obj, parameters_id), depth, out, true);
}
free(cols);
}

typedef struct _NamedFunc {
const char *name;
DumpFunc func;
} *NamedFunc;

static struct _NamedFunc dump_map[] = {
{ "ActionController::Parameters", dump_actioncontroller_parameters },
{ "ActiveSupport::Result", dump_activesupport_result },
{ "ActiveSupport::TimeWithZone", dump_timewithzone },
{ "BigDecimal", dump_bigdecimal },
{ "Range", dump_to_s },
Expand Down

0 comments on commit a81efb8

Please sign in to comment.