Class: JsonWriteStream::StatefulArrayWriter

Inherits:
StatefulWriter show all
Defined in:
lib/json-write-stream/stateful.rb

Instance Attribute Summary

Attributes inherited from StatefulWriter

#closed, #index, #stack, #stream

Instance Method Summary collapse

Methods inherited from StatefulWriter

#close_array, #close_object, #eos?, #flush, #in_array?, #in_object?, #initialize, #write_key_value

Constructor Details

This class inherits a constructor from JsonWriteStream::StatefulWriter

Instance Method Details

#after_initializeObject



177
178
179
# File 'lib/json-write-stream/stateful.rb', line 177

def after_initialize
  stream.write('[')
end

#closeObject



200
201
202
# File 'lib/json-write-stream/stateful.rb', line 200

def close
  stream.write(']')
end

#is_array?Boolean

Returns:

  • (Boolean)


208
209
210
# File 'lib/json-write-stream/stateful.rb', line 208

def is_array?
  true
end

#is_object?Boolean

Returns:

  • (Boolean)


204
205
206
# File 'lib/json-write-stream/stateful.rb', line 204

def is_object?
  false
end

#write_arrayObject

prep work



189
190
191
192
# File 'lib/json-write-stream/stateful.rb', line 189

def write_array
  write_comma
  increment
end

#write_element(element, options = DEFAULT_OPTIONS) ⇒ Object



181
182
183
184
185
186
# File 'lib/json-write-stream/stateful.rb', line 181

def write_element(element, options = DEFAULT_OPTIONS)
  write_comma
  stream.write(options.fetch(:before, DEFAULT_OPTIONS[:before]))
  increment
  stream.write(escape(element))
end

#write_objectObject

prep work



195
196
197
198
# File 'lib/json-write-stream/stateful.rb', line 195

def write_object
  write_comma
  increment
end