From 8887402ca81f3d4c63c10126577861711475e80c Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Tue, 26 Apr 2011 07:46:38 -0400 Subject: [PATCH] Don't modify hash arguments. --- lib/mongo/collection.rb | 8 +++++--- lib/mongo/gridfs/grid.rb | 2 +- lib/mongo/gridfs/grid_file_system.rb | 1 + lib/mongo/gridfs/grid_io.rb | 2 ++ 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/mongo/collection.rb b/lib/mongo/collection.rb index 6283206..d922aa8 100644 --- a/lib/mongo/collection.rb +++ b/lib/mongo/collection.rb @@ -172,6 +172,7 @@ module Mongo # # @core find find-instance_method def find(selector={}, opts={}) + opts = opts.dup fields = opts.delete(:fields) fields = ["_id"] if fields && fields.empty? skip = opts.delete(:skip) || skip || 0 @@ -437,8 +438,9 @@ module Mongo # # @core indexes create_index-instance_method def create_index(spec, opts={}) - opts[:dropDups] = opts.delete(:drop_dups) if opts[:drop_dups] + opts[:dropDups] = opts[:drop_dups] if opts[:drop_dups] field_spec = parse_index_spec(spec) + opts = opts.dup name = opts.delete(:name) || generate_index_name(field_spec) name = name.to_s if name @@ -466,7 +468,7 @@ module Mongo now = Time.now.utc.to_i field_spec = parse_index_spec(spec) - name = opts.delete(:name) || generate_index_name(field_spec) + name = opts[:name] || generate_index_name(field_spec) name = name.to_s if name if !@cache[name] || @cache[name] <= now @@ -559,7 +561,7 @@ module Mongo def map_reduce(map, reduce, opts={}) map = BSON::Code.new(map) unless map.is_a?(BSON::Code) reduce = BSON::Code.new(reduce) unless reduce.is_a?(BSON::Code) - raw = opts.delete(:raw) + raw = opts[:raw] hash = BSON::OrderedHash.new hash['mapreduce'] = self.name diff --git a/lib/mongo/gridfs/grid.rb b/lib/mongo/gridfs/grid.rb index 863ebb1..0590195 100644 --- a/lib/mongo/gridfs/grid.rb +++ b/lib/mongo/gridfs/grid.rb @@ -65,7 +65,7 @@ module Mongo # # @return [Mongo::ObjectId] the file's id. def put(data, opts={}) - filename = opts.delete :filename + filename = opts[:filename] opts.merge!(default_grid_io_opts) file = GridIO.new(@files, @chunks, filename, 'w', opts=opts) file.write(data) diff --git a/lib/mongo/gridfs/grid_file_system.rb b/lib/mongo/gridfs/grid_file_system.rb index f4f9d2b..b4ccd84 100644 --- a/lib/mongo/gridfs/grid_file_system.rb +++ b/lib/mongo/gridfs/grid_file_system.rb @@ -93,6 +93,7 @@ module Mongo # # @return [Mongo::GridIO] def open(filename, mode, opts={}) + opts = opts.dup opts.merge!(default_grid_io_opts(filename)) del = opts.delete(:delete_old) && mode == 'w' file = GridIO.new(@files, @chunks, filename, mode, opts) diff --git a/lib/mongo/gridfs/grid_io.rb b/lib/mongo/gridfs/grid_io.rb index 89af77d..87cb178 100644 --- a/lib/mongo/gridfs/grid_io.rb +++ b/lib/mongo/gridfs/grid_io.rb @@ -55,6 +55,7 @@ module Mongo @chunks = chunks @filename = filename @mode = mode + opts = opts.dup @query = opts.delete(:query) || {} @query_opts = opts.delete(:query_opts) || {} @fs_name = opts.delete(:fs_name) || Grid::DEFAULT_FS_NAME @@ -410,6 +411,7 @@ module Mongo # Initialize the class for writing a file. def init_write(opts) + opts = opts.dup @files_id = opts.delete(:_id) || BSON::ObjectId.new @content_type = opts.delete(:content_type) || (defined? MIME) && get_content_type || DEFAULT_CONTENT_TYPE @chunk_size = opts.delete(:chunk_size) || DEFAULT_CHUNK_SIZE