Class: JSON::Ext::Generator::State
- Defined in:
- lib/json/ext/generator/state.rb,
ext/json/ext/generator/generator.c
Class Method Summary collapse
- ._generate_no_fallback(obj, opts, io) ⇒ Object
- .default_sort_keys_proc=(proc) ⇒ Object
- .from_state(opts) ⇒ Object
- .generate(obj, opts, io) ⇒ Object
Instance Method Summary collapse
- #_generate_no_fallback(*args) ⇒ Object
- #allow_nan=(enable) ⇒ Object
- #allow_nan? ⇒ Object
- #array_nl ⇒ Object
- #array_nl=(array_nl) ⇒ Object
- #as_json ⇒ Object
- #as_json=(as_json) ⇒ Object
- #ascii_only=(enable) ⇒ Object
- #ascii_only? ⇒ Object
- #buffer_initial_length ⇒ Object
- #buffer_initial_length=(buffer_initial_length) ⇒ Object
- #check_circular? ⇒ Object
-
#configure(opts) ⇒ Object
(also: #merge)
call-seq: configure(opts).
- #depth ⇒ Object
- #depth=(depth) ⇒ Object
- #generate(*args) ⇒ Object
- #indent ⇒ Object
- #indent=(indent) ⇒ Object
- #initialize_copy(orig) ⇒ Object
- #max_nesting ⇒ Object
- #max_nesting=(depth) ⇒ Object
- #object_nl ⇒ Object
- #object_nl=(object_nl) ⇒ Object
- #script_safe ⇒ Object
- #script_safe=(enable) ⇒ Object
- #script_safe? ⇒ Object
- #sort_keys ⇒ Object
- #sort_keys=(value) ⇒ Object
- #space ⇒ Object
- #space=(space) ⇒ Object
- #space_before ⇒ Object
- #space_before=(space_before) ⇒ Object
- #strict ⇒ Object
- #strict=(enable) ⇒ Object
- #strict? ⇒ Object
-
#to_h ⇒ Object
(also: #to_hash)
call-seq: to_h.
Class Method Details
._generate_no_fallback(obj, opts, io) ⇒ Object
1946 1947 1948 1949 |
# File 'ext/json/ext/generator/generator.c', line 1946
static VALUE cState_m_generate_no_fallback(VALUE klass, VALUE obj, VALUE opts, VALUE io)
{
return cState_m_do_generate(klass, obj, opts, io, generate_json_no_fallback);
}
|
.default_sort_keys_proc=(proc) ⇒ Object
1727 1728 1729 1730 1731 1732 1733 |
# File 'ext/json/ext/generator/generator.c', line 1727
static VALUE cState_set_default_sort_keys_proc(VALUE self, VALUE proc)
{
if (!rb_obj_is_proc(proc)) {
rb_raise(rb_eTypeError, "sort_key_proc must be a Proc");
}
return default_sort_keys_proc = proc;
}
|
.from_state(opts) ⇒ Object
1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 |
# File 'ext/json/ext/generator/generator.c', line 1392
static VALUE cState_from_state_s(VALUE self, VALUE opts)
{
if (rb_obj_is_kind_of(opts, self)) {
return opts;
} else if (rb_obj_is_kind_of(opts, rb_cHash)) {
return rb_funcall(self, i_new, 1, opts);
} else {
return rb_class_new_instance(0, NULL, cState);
}
}
|
.generate(obj, opts, io) ⇒ Object
1941 1942 1943 1944 |
# File 'ext/json/ext/generator/generator.c', line 1941
static VALUE cState_m_generate(VALUE klass, VALUE obj, VALUE opts, VALUE io)
{
return cState_m_do_generate(klass, obj, opts, io, generate_json);
}
|
Instance Method Details
#_generate_no_fallback(*args) ⇒ Object
1343 1344 1345 1346 1347 1348 1349 |
# File 'ext/json/ext/generator/generator.c', line 1343
static VALUE cState_generate_no_fallback(int argc, VALUE *argv, VALUE self)
{
rb_check_arity(argc, 1, 2);
VALUE obj = argv[0];
VALUE io = argc > 1 ? argv[1] : Qnil;
return cState_partial_generate(self, obj, generate_json_no_fallback, io);
}
|
#allow_nan=(enable) ⇒ Object
1694 1695 1696 1697 1698 1699 1700 |
# File 'ext/json/ext/generator/generator.c', line 1694
static VALUE cState_allow_nan_set(VALUE self, VALUE enable)
{
rb_check_frozen(self);
GET_STATE(self);
state->allow_nan = RTEST(enable);
return Qnil;
}
|
#allow_nan? ⇒ Object
1683 1684 1685 1686 1687 |
# File 'ext/json/ext/generator/generator.c', line 1683
static VALUE cState_allow_nan_p(VALUE self)
{
GET_STATE(self);
return state->allow_nan ? Qtrue : Qfalse;
}
|
#array_nl ⇒ Object
1519 1520 1521 1522 1523 |
# File 'ext/json/ext/generator/generator.c', line 1519
static VALUE cState_array_nl(VALUE self)
{
GET_STATE(self);
return state->array_nl ? state->array_nl : rb_str_freeze(rb_utf8_str_new("", 0));
}
|
#array_nl=(array_nl) ⇒ Object
1530 1531 1532 1533 1534 1535 1536 |
# File 'ext/json/ext/generator/generator.c', line 1530
static VALUE cState_array_nl_set(VALUE self, VALUE array_nl)
{
rb_check_frozen(self);
GET_STATE(self);
RB_OBJ_WRITE(self, &state->array_nl, string_config(array_nl));
return Qnil;
}
|
#as_json ⇒ Object
1543 1544 1545 1546 1547 |
# File 'ext/json/ext/generator/generator.c', line 1543
static VALUE cState_as_json(VALUE self)
{
GET_STATE(self);
return state->as_json;
}
|
#as_json=(as_json) ⇒ Object
1554 1555 1556 1557 1558 1559 1560 |
# File 'ext/json/ext/generator/generator.c', line 1554
static VALUE cState_as_json_set(VALUE self, VALUE as_json)
{
rb_check_frozen(self);
GET_STATE(self);
RB_OBJ_WRITE(self, &state->as_json, rb_convert_type(as_json, T_DATA, "Proc", "to_proc"));
return Qnil;
}
|
#ascii_only=(enable) ⇒ Object
1719 1720 1721 1722 1723 1724 1725 |
# File 'ext/json/ext/generator/generator.c', line 1719
static VALUE cState_ascii_only_set(VALUE self, VALUE enable)
{
rb_check_frozen(self);
GET_STATE(self);
state->ascii_only = RTEST(enable);
return Qnil;
}
|
#ascii_only? ⇒ Object
1708 1709 1710 1711 1712 |
# File 'ext/json/ext/generator/generator.c', line 1708
static VALUE cState_ascii_only_p(VALUE self)
{
GET_STATE(self);
return state->ascii_only ? Qtrue : Qfalse;
}
|
#buffer_initial_length ⇒ Object
1812 1813 1814 1815 1816 |
# File 'ext/json/ext/generator/generator.c', line 1812
static VALUE cState_buffer_initial_length(VALUE self)
{
GET_STATE(self);
return LONG2FIX(state->buffer_initial_length);
}
|
#buffer_initial_length=(buffer_initial_length) ⇒ Object
1833 1834 1835 1836 1837 1838 1839 |
# File 'ext/json/ext/generator/generator.c', line 1833
static VALUE cState_buffer_initial_length_set(VALUE self, VALUE buffer_initial_length)
{
rb_check_frozen(self);
GET_STATE(self);
buffer_initial_length_set(state, buffer_initial_length);
return Qnil;
}
|
#check_circular? ⇒ Object
1568 1569 1570 1571 1572 |
# File 'ext/json/ext/generator/generator.c', line 1568
static VALUE cState_check_circular_p(VALUE self)
{
GET_STATE(self);
return state->max_nesting ? Qtrue : Qfalse;
}
|
#configure(opts) ⇒ Object Also known as: merge
call-seq: configure(opts)
Configure this State instance with the Hash opts, and return itself.
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/json/ext/generator/state.rb', line 23 def configure(opts) unless opts.is_a?(Hash) if opts.respond_to?(:to_hash) opts = opts.to_hash elsif opts.respond_to?(:to_h) opts = opts.to_h else raise TypeError, "can't convert #{opts.class} into Hash" end end _configure(opts) end |
#depth ⇒ Object
1787 1788 1789 1790 1791 |
# File 'ext/json/ext/generator/generator.c', line 1787
static VALUE cState_depth(VALUE self)
{
GET_STATE(self);
return LONG2FIX(state->depth);
}
|
#depth=(depth) ⇒ Object
1799 1800 1801 1802 1803 1804 1805 |
# File 'ext/json/ext/generator/generator.c', line 1799
static VALUE cState_depth_set(VALUE self, VALUE depth)
{
rb_check_frozen(self);
GET_STATE(self);
state->depth = depth_config(depth);
return Qnil;
}
|
#generate(*args) ⇒ Object
1334 1335 1336 1337 1338 1339 1340 |
# File 'ext/json/ext/generator/generator.c', line 1334
static VALUE cState_generate(int argc, VALUE *argv, VALUE self)
{
rb_check_arity(argc, 1, 2);
VALUE obj = argv[0];
VALUE io = argc > 1 ? argv[1] : Qnil;
return cState_partial_generate(self, obj, generate_json, io);
}
|
#indent ⇒ Object
1408 1409 1410 1411 1412 |
# File 'ext/json/ext/generator/generator.c', line 1408
static VALUE cState_indent(VALUE self)
{
GET_STATE(self);
return state->indent ? state->indent : rb_str_freeze(rb_utf8_str_new("", 0));
}
|
#indent=(indent) ⇒ Object
1430 1431 1432 1433 1434 1435 1436 |
# File 'ext/json/ext/generator/generator.c', line 1430
static VALUE cState_indent_set(VALUE self, VALUE indent)
{
rb_check_frozen(self);
GET_STATE(self);
RB_OBJ_WRITE(self, &state->indent, string_config(indent));
return Qnil;
}
|
#initialize_copy(orig) ⇒ Object
1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 |
# File 'ext/json/ext/generator/generator.c', line 1363
static VALUE cState_init_copy(VALUE obj, VALUE orig)
{
JSON_Generator_State *objState, *origState;
if (obj == orig) return obj;
GET_STATE_TO(obj, objState);
GET_STATE_TO(orig, origState);
if (!objState) rb_raise(rb_eArgError, "unallocated JSON::State");
MEMCPY(objState, origState, JSON_Generator_State, 1);
RB_OBJ_WRITTEN(obj, Qundef, objState->indent);
RB_OBJ_WRITTEN(obj, Qundef, objState->space);
RB_OBJ_WRITTEN(obj, Qundef, objState->space_before);
RB_OBJ_WRITTEN(obj, Qundef, objState->object_nl);
RB_OBJ_WRITTEN(obj, Qundef, objState->array_nl);
RB_OBJ_WRITTEN(obj, Qundef, objState->as_json);
RB_OBJ_WRITTEN(obj, Qundef, objState->sort_keys);
return obj;
}
|
#max_nesting ⇒ Object
1580 1581 1582 1583 1584 |
# File 'ext/json/ext/generator/generator.c', line 1580
static VALUE cState_max_nesting(VALUE self)
{
GET_STATE(self);
return LONG2FIX(state->max_nesting);
}
|
#max_nesting=(depth) ⇒ Object
1611 1612 1613 1614 1615 1616 1617 |
# File 'ext/json/ext/generator/generator.c', line 1611
static VALUE cState_max_nesting_set(VALUE self, VALUE depth)
{
rb_check_frozen(self);
GET_STATE(self);
state->max_nesting = long_config(depth);
return Qnil;
}
|
#object_nl ⇒ Object
1494 1495 1496 1497 1498 |
# File 'ext/json/ext/generator/generator.c', line 1494
static VALUE cState_object_nl(VALUE self)
{
GET_STATE(self);
return state->object_nl ? state->object_nl : rb_str_freeze(rb_utf8_str_new("", 0));
}
|
#object_nl=(object_nl) ⇒ Object
1506 1507 1508 1509 1510 1511 1512 |
# File 'ext/json/ext/generator/generator.c', line 1506
static VALUE cState_object_nl_set(VALUE self, VALUE object_nl)
{
rb_check_frozen(self);
GET_STATE(self);
RB_OBJ_WRITE(self, &state->object_nl, string_config(object_nl));
return Qnil;
}
|
#script_safe ⇒ Object
1625 1626 1627 1628 1629 |
# File 'ext/json/ext/generator/generator.c', line 1625
static VALUE cState_script_safe(VALUE self)
{
GET_STATE(self);
return state->script_safe ? Qtrue : Qfalse;
}
|
#script_safe=(enable) ⇒ Object
1637 1638 1639 1640 1641 1642 1643 |
# File 'ext/json/ext/generator/generator.c', line 1637
static VALUE cState_script_safe_set(VALUE self, VALUE enable)
{
rb_check_frozen(self);
GET_STATE(self);
state->script_safe = RTEST(enable);
return Qnil;
}
|
#script_safe? ⇒ Object
1625 1626 1627 1628 1629 |
# File 'ext/json/ext/generator/generator.c', line 1625
static VALUE cState_script_safe(VALUE self)
{
GET_STATE(self);
return state->script_safe ? Qtrue : Qfalse;
}
|
#sort_keys ⇒ Object
1753 1754 1755 1756 1757 |
# File 'ext/json/ext/generator/generator.c', line 1753
static VALUE cState_sort_keys_p(VALUE self)
{
GET_STATE(self);
return state->sort_keys;
}
|
#sort_keys=(value) ⇒ Object
1768 1769 1770 1771 1772 1773 1774 |
# File 'ext/json/ext/generator/generator.c', line 1768
static VALUE cState_sort_keys_set(VALUE self, VALUE value)
{
rb_check_frozen(self);
GET_STATE(self);
RB_OBJ_WRITE(self, &state->sort_keys, normalize_sort_keys(value));
return Qnil;
}
|
#space ⇒ Object
1444 1445 1446 1447 1448 |
# File 'ext/json/ext/generator/generator.c', line 1444
static VALUE cState_space(VALUE self)
{
GET_STATE(self);
return state->space ? state->space : rb_str_freeze(rb_utf8_str_new("", 0));
}
|
#space=(space) ⇒ Object
1456 1457 1458 1459 1460 1461 1462 |
# File 'ext/json/ext/generator/generator.c', line 1456
static VALUE cState_space_set(VALUE self, VALUE space)
{
rb_check_frozen(self);
GET_STATE(self);
RB_OBJ_WRITE(self, &state->space, string_config(space));
return Qnil;
}
|
#space_before ⇒ Object
1469 1470 1471 1472 1473 |
# File 'ext/json/ext/generator/generator.c', line 1469
static VALUE cState_space_before(VALUE self)
{
GET_STATE(self);
return state->space_before ? state->space_before : rb_str_freeze(rb_utf8_str_new("", 0));
}
|
#space_before=(space_before) ⇒ Object
1480 1481 1482 1483 1484 1485 1486 |
# File 'ext/json/ext/generator/generator.c', line 1480
static VALUE cState_space_before_set(VALUE self, VALUE space_before)
{
rb_check_frozen(self);
GET_STATE(self);
RB_OBJ_WRITE(self, &state->space_before, string_config(space_before));
return Qnil;
}
|
#strict ⇒ Object
1653 1654 1655 1656 1657 |
# File 'ext/json/ext/generator/generator.c', line 1653
static VALUE cState_strict(VALUE self)
{
GET_STATE(self);
return state->strict ? Qtrue : Qfalse;
}
|
#strict=(enable) ⇒ Object
1669 1670 1671 1672 1673 1674 1675 |
# File 'ext/json/ext/generator/generator.c', line 1669
static VALUE cState_strict_set(VALUE self, VALUE enable)
{
rb_check_frozen(self);
GET_STATE(self);
state->strict = RTEST(enable);
return Qnil;
}
|
#strict? ⇒ Object
1653 1654 1655 1656 1657 |
# File 'ext/json/ext/generator/generator.c', line 1653
static VALUE cState_strict(VALUE self)
{
GET_STATE(self);
return state->strict ? Qtrue : Qfalse;
}
|
#to_h ⇒ Object Also known as: to_hash
call-seq: to_h
Returns the configuration instance variables as a hash, that can be passed to the configure method.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/json/ext/generator/state.rb', line 42 def to_h result = { indent: indent, space: space, space_before: space_before, object_nl: object_nl, array_nl: array_nl, as_json: as_json, allow_nan: allow_nan?, ascii_only: ascii_only?, max_nesting: max_nesting, script_safe: script_safe?, strict: strict?, depth: depth, buffer_initial_length: buffer_initial_length, sort_keys: sort_keys } allow_duplicate_key = allow_duplicate_key? unless allow_duplicate_key.nil? result[:allow_duplicate_key] = allow_duplicate_key end instance_variables.each do |iv| iv = iv.to_s[1..-1] result[iv.to_sym] = self[iv] end result end |