lib/json-write-stream/yielding.rb in json-write-stream-1.1.0 vs lib/json-write-stream/yielding.rb in json-write-stream-1.2.0
- old
+ new
@@ -58,34 +58,38 @@
class YieldingObjectWriter < YieldingWriter
def after_initialize
stream.write('{')
end
- def write_array(key, before = '')
+ def write_array(key, options = DEFAULT_OPTIONS)
write_comma
- stream.write(before)
+ 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
- def write_object(key, before = '')
+ def write_object(key, options = DEFAULT_OPTIONS)
write_comma
- stream.write(before)
+ 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
- def write_key_value(key, value, before = '')
+ def write_key_value(key, value, options = DEFAULT_OPTIONS)
write_comma
- stream.write(before)
+ stream.write(options.fetch(:before, DEFAULT_OPTIONS[:before]))
increment
write_key(key)
- stream.write(":#{escape(value)}")
+ stream.write(':')
+ stream.write(options.fetch(:between, DEFAULT_OPTIONS[:between]))
+ stream.write(escape(value))
end
def close
stream.write('}')
end
@@ -100,12 +104,12 @@
class YieldingArrayWriter < YieldingWriter
def after_initialize
stream.write('[')
end
- def write_element(element, before = '')
+ def write_element(element, options = DEFAULT_OPTIONS)
write_comma
- stream.write(before)
+ stream.write(options.fetch(:before, DEFAULT_OPTIONS[:before]))
increment
stream.write(escape(element))
end
def close