Don't modify hash arguments.

This commit is contained in:
Kyle Banker 2011-04-26 07:46:38 -04:00
parent 9cc6bad613
commit 8887402ca8
4 changed files with 9 additions and 4 deletions

View File

@ -172,6 +172,7 @@ module Mongo
# #
# @core find find-instance_method # @core find find-instance_method
def find(selector={}, opts={}) def find(selector={}, opts={})
opts = opts.dup
fields = opts.delete(:fields) fields = opts.delete(:fields)
fields = ["_id"] if fields && fields.empty? fields = ["_id"] if fields && fields.empty?
skip = opts.delete(:skip) || skip || 0 skip = opts.delete(:skip) || skip || 0
@ -437,8 +438,9 @@ module Mongo
# #
# @core indexes create_index-instance_method # @core indexes create_index-instance_method
def create_index(spec, opts={}) 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) field_spec = parse_index_spec(spec)
opts = opts.dup
name = opts.delete(:name) || generate_index_name(field_spec) name = opts.delete(:name) || generate_index_name(field_spec)
name = name.to_s if name name = name.to_s if name
@ -466,7 +468,7 @@ module Mongo
now = Time.now.utc.to_i now = Time.now.utc.to_i
field_spec = parse_index_spec(spec) 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 name = name.to_s if name
if !@cache[name] || @cache[name] <= now if !@cache[name] || @cache[name] <= now
@ -559,7 +561,7 @@ module Mongo
def map_reduce(map, reduce, opts={}) def map_reduce(map, reduce, opts={})
map = BSON::Code.new(map) unless map.is_a?(BSON::Code) map = BSON::Code.new(map) unless map.is_a?(BSON::Code)
reduce = BSON::Code.new(reduce) unless reduce.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 = BSON::OrderedHash.new
hash['mapreduce'] = self.name hash['mapreduce'] = self.name

View File

@ -65,7 +65,7 @@ module Mongo
# #
# @return [Mongo::ObjectId] the file's id. # @return [Mongo::ObjectId] the file's id.
def put(data, opts={}) def put(data, opts={})
filename = opts.delete :filename filename = opts[:filename]
opts.merge!(default_grid_io_opts) opts.merge!(default_grid_io_opts)
file = GridIO.new(@files, @chunks, filename, 'w', opts=opts) file = GridIO.new(@files, @chunks, filename, 'w', opts=opts)
file.write(data) file.write(data)

View File

@ -93,6 +93,7 @@ module Mongo
# #
# @return [Mongo::GridIO] # @return [Mongo::GridIO]
def open(filename, mode, opts={}) def open(filename, mode, opts={})
opts = opts.dup
opts.merge!(default_grid_io_opts(filename)) opts.merge!(default_grid_io_opts(filename))
del = opts.delete(:delete_old) && mode == 'w' del = opts.delete(:delete_old) && mode == 'w'
file = GridIO.new(@files, @chunks, filename, mode, opts) file = GridIO.new(@files, @chunks, filename, mode, opts)

View File

@ -55,6 +55,7 @@ module Mongo
@chunks = chunks @chunks = chunks
@filename = filename @filename = filename
@mode = mode @mode = mode
opts = opts.dup
@query = opts.delete(:query) || {} @query = opts.delete(:query) || {}
@query_opts = opts.delete(:query_opts) || {} @query_opts = opts.delete(:query_opts) || {}
@fs_name = opts.delete(:fs_name) || Grid::DEFAULT_FS_NAME @fs_name = opts.delete(:fs_name) || Grid::DEFAULT_FS_NAME
@ -410,6 +411,7 @@ module Mongo
# Initialize the class for writing a file. # Initialize the class for writing a file.
def init_write(opts) def init_write(opts)
opts = opts.dup
@files_id = opts.delete(:_id) || BSON::ObjectId.new @files_id = opts.delete(:_id) || BSON::ObjectId.new
@content_type = opts.delete(:content_type) || (defined? MIME) && get_content_type || DEFAULT_CONTENT_TYPE @content_type = opts.delete(:content_type) || (defined? MIME) && get_content_type || DEFAULT_CONTENT_TYPE
@chunk_size = opts.delete(:chunk_size) || DEFAULT_CHUNK_SIZE @chunk_size = opts.delete(:chunk_size) || DEFAULT_CHUNK_SIZE