summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFlorian Frank <flori@ping.de>2010-08-07 01:18:56 +0200
committerFlorian Frank <flori@ping.de>2010-08-07 01:20:52 +0200
commit310c96b4134f8c0f5d63822a25ccdbc83c30e86e (patch)
tree8f8f34719090dc0d272ce564135f3f203ad5e0cb /lib
parentf8fcc04c9f1d5de3c035a71a507af5023a0406b0 (diff)
downloadjson-310c96b4134f8c0f5d63822a25ccdbc83c30e86e.tar.gz
added missing methods to State + tests
Diffstat (limited to 'lib')
-rw-r--r--lib/json/pure/generator.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/json/pure/generator.rb b/lib/json/pure/generator.rb
index 0584108..12959bf 100644
--- a/lib/json/pure/generator.rb
+++ b/lib/json/pure/generator.rb
@@ -163,6 +163,10 @@ module JSON
# the generated JSON, max_nesting = 0 if no maximum is checked.
attr_accessor :max_nesting
+ # This integer returns the current depth data structure nesting in the
+ # generated JSON.
+ attr_accessor :depth
+
def check_max_nesting(depth) # :nodoc:
return if @max_nesting.zero?
current_nesting = depth + 1
@@ -196,6 +200,7 @@ module JSON
@array_nl = opts[:array_nl] if opts.key?(:array_nl)
@allow_nan = !!opts[:allow_nan] if opts.key?(:allow_nan)
@ascii_only = opts[:ascii_only] if opts.key?(:ascii_only)
+ @depth = opts[:depth] || 0
if !opts.key?(:max_nesting) # defaults to 19
@max_nesting = 19
elsif opts[:max_nesting]
@@ -210,7 +215,7 @@ module JSON
# passed to the configure method.
def to_h
result = {}
- for iv in %w[indent space space_before object_nl array_nl allow_nan max_nesting]
+ for iv in %w[indent space space_before object_nl array_nl allow_nan max_nesting ascii_only depth]
result[iv.intern] = instance_variable_get("@#{iv}")
end
result