Class: JsonWriteStream::YieldingObjectWriter

Inherits:
YieldingWriter show all
Defined in:
lib/json-write-stream/yielding.rb

Instance Attribute Summary

Attributes inherited from YieldingWriter

#index, #stream

Instance Method Summary collapse

Methods inherited from YieldingWriter

#flush, #initialize

Constructor Details

This class inherits a constructor from JsonWriteStream::YieldingWriter

Instance Method Details

#after_initializeObject



59
60
61
# File 'lib/json-write-stream/yielding.rb', line 59

def after_initialize
  stream.write('{')
end

#closeObject



93
94
95
# File 'lib/json-write-stream/yielding.rb', line 93

def close
  stream.write('}')
end

#write_array(key, options = DEFAULT_OPTIONS) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/json-write-stream/yielding.rb', line 63

def write_array(key, options = DEFAULT_OPTIONS)
  write_comma
  stream.write(options.fetch(:before, DEFAULT_OPTIONS[:before]))
  increment
  write_key(key)
  stream.write(':')
  stream.write(options.fetch(:between, DEFAULT_OPTIONS[:between]))
  super(true)
end

#write_key_value(key, value, options = DEFAULT_OPTIONS) ⇒ Object



83
84
85
86
87
88
89
90
91
# File 'lib/json-write-stream/yielding.rb', line 83

def write_key_value(key, value, options = DEFAULT_OPTIONS)
  write_comma
  stream.write(options.fetch(:before, DEFAULT_OPTIONS[:before]))
  increment
  write_key(key)
  stream.write(':')
  stream.write(options.fetch(:between, DEFAULT_OPTIONS[:between]))
  stream.write(escape(value))
end

#write_object(key, options = DEFAULT_OPTIONS) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'lib/json-write-stream/yielding.rb', line 73

def write_object(key, options = DEFAULT_OPTIONS)
  write_comma
  stream.write(options.fetch(:before, DEFAULT_OPTIONS[:before]))
  increment
  write_key(key)
  stream.write(':')
  stream.write(options.fetch(:between, DEFAULT_OPTIONS[:between]))
  super(true)
end