lib/json-write-stream.rb in json-write-stream-1.2.0 vs lib/json-write-stream.rb in json-write-stream-2.0.0

- old
+ new

@@ -4,32 +4,33 @@ require 'json-write-stream/yielding' require 'json-write-stream/stateful' class JsonWriteStream DEFAULT_ENCODING = Encoding::UTF_8 - DEFAULT_OPTIONS = { before: '', between: '' }.freeze class << self - def from_stream(stream, encoding = DEFAULT_ENCODING) + def from_stream(stream, options = {}) + encoding = options.fetch(:encoding, DEFAULT_ENCODING) stream.set_encoding(encoding) if block_given? yield writer = YieldingWriter.new(stream) writer.close else - StatefulWriter.new(stream) + StatefulWriter.new(stream, options) end end - def open(file, encoding = DEFAULT_ENCODING) + def open(file, options = {}) + encoding = options.fetch(:encoding, DEFAULT_ENCODING) handle = File.open(file, 'w') handle.set_encoding(encoding) if block_given? yield writer = YieldingWriter.new(handle) writer.close else - StatefulWriter.new(handle) + StatefulWriter.new(handle, options) end end end end