lib/mongo/grid/stream/write.rb in mongo-2.2.7 vs lib/mongo/grid/stream/write.rb in mongo-2.3.0
- old
+ new
@@ -1,6 +1,6 @@
-# Copyright (C) 2014-2015 MongoDB, Inc.
+# Copyright (C) 2014-2016 MongoDB, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
@@ -25,11 +25,11 @@
# @return [ FSBucket ] fs The fs bucket to which this stream writes.
#
# @since 2.1.0
attr_reader :fs
- # @return [ BSON::ObjectId ] file_id The id of the file being uploaded.
+ # @return [ Object ] file_id The id of the file being uploaded.
#
# @since 2.1.0
attr_reader :file_id
# @return [ String ] filename The name of the file being uploaded.
@@ -48,10 +48,11 @@
# 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 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.
@@ -61,10 +62,10 @@
# @since 2.1.0
def initialize(fs, options)
@fs = fs
@length = 0
@n = 0
- @file_id = BSON::ObjectId.new
+ @file_id = options[:file_id] || BSON::ObjectId.new
@options = options
@filename = @options[:filename]
@open = true
end