lib/mongo/grid/stream/write.rb in mongo-2.9.2 vs lib/mongo/grid/stream/write.rb in mongo-2.10.0.rc0
- old
+ new
@@ -48,26 +48,38 @@
# Stream::Write.new(fs, options)
#
# @param [ FSBucket ] fs The GridFS bucket object.
# @param [ Hash ] options The write stream options.
#
- # @option opts [ Object ] :file_id The file id. An ObjectId is generated otherwise.
+ # @option options [ Object ] :file_id The file id. An ObjectId
+ # is generated if the file id is not provided.
# @option opts [ Integer ] :chunk_size Override the default chunk size.
- # @option opts [ Hash ] :write The write concern.
# @option opts [ Hash ] :metadata User data for the 'metadata' field of the files collection document.
# @option opts [ String ] :content_type The content type of the file.
# Deprecated, please use the metadata document instead.
# @option opts [ Array<String> ] :aliases A list of aliases.
# Deprecated, please use the metadata document instead.
+ # @option options [ Hash ] :write Deprecated. Equivalent to :write_concern
+ # option.
+ # @option options [ Hash ] :write_concern The write concern options.
+ # Can be :w => Integer|String, :fsync => Boolean, :j => Boolean.
#
# @since 2.1.0
def initialize(fs, options)
@fs = fs
@length = 0
@n = 0
@file_id = options[:file_id] || BSON::ObjectId.new
- @options = options
+ @options = options.dup
+=begin WriteConcern object support
+ if @options[:write_concern].is_a?(WriteConcern::Base)
+ # Cache the instance so that we do not needlessly reconstruct it.
+ @write_concern = @options[:write_concern]
+ @options[:write_concern] = @write_concern.options
+ end
+=end
+ @options.freeze
@filename = @options[:filename]
@open = true
end
# Write to the GridFS bucket from the source stream.
@@ -115,12 +127,15 @@
#
# @return [ Mongo::WriteConcern ] The write concern.
#
# @since 2.1.0
def write_concern
- @write_concern ||= @options[:write] ? WriteConcern.get(@options[:write]) :
+ @write_concern ||= if wco = @options[:write_concern] || @options[:write]
+ WriteConcern.get(wco)
+ else
fs.write_concern
+ end
end
# Is the stream closed.
#
# @example Is the stream closed.
@@ -156,10 +171,11 @@
with_write_concern(fs.files_collection)
end
def with_write_concern(collection)
if write_concern.nil? || (collection.write_concern &&
- collection.write_concern.options == write_concern.options)
+ collection.write_concern.options == write_concern.options)
+ then
collection
else
collection.with(write: write_concern.options)
end
end