diff options
Diffstat (limited to 'lib/json/pure/generator.rb')
-rw-r--r-- | lib/json/pure/generator.rb | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/lib/json/pure/generator.rb b/lib/json/pure/generator.rb index 7c9b2ad..9141ae5 100644 --- a/lib/json/pure/generator.rb +++ b/lib/json/pure/generator.rb @@ -136,14 +136,15 @@ module JSON # * *quirks_mode*: Enables quirks_mode for parser, that is for example # generating single JSON values instead of documents is possible. def initialize(opts = {}) - @indent = '' - @space = '' - @space_before = '' - @object_nl = '' - @array_nl = '' - @allow_nan = false - @ascii_only = false - @quirks_mode = false + @indent = '' + @space = '' + @space_before = '' + @object_nl = '' + @array_nl = '' + @allow_nan = false + @ascii_only = false + @quirks_mode = false + @buffer_initial_length = 1024 configure opts end @@ -172,6 +173,16 @@ module JSON # it's disabled. attr_accessor :quirks_mode + # :stopdoc: + attr_reader :buffer_initial_length + + def buffer_initial_length=(length) + if length > 0 + @buffer_initial_length = length + end + end + # :startdoc: + # This integer returns the current depth data structure nesting in the # generated JSON. attr_accessor :depth @@ -233,7 +244,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 ascii_only quirks_mode depth] + for iv in %w[indent space space_before object_nl array_nl allow_nan max_nesting ascii_only quirks_mode buffer_initial_length depth] result[iv.intern] = instance_variable_get("@#{iv}") end result |