Permalink
Browse files

Support new object key parameter

  • Loading branch information...
1 parent 5b07e50 commit beac52e06a201639c2315fbff76b486fe374ecb7 @jnunemaker committed Sep 10, 2012
@@ -21,7 +21,7 @@ def write(key, value)
end
def delete(key)
- @collection.remove criteria(key)
+ remove key
end
def set_members(key)
@@ -39,7 +39,9 @@ def set_delete(key, value)
private
def find_one(key)
- if (doc = @collection.find_one(criteria(key)))
+ doc = @collection.find_one(criteria(key))
+
+ unless doc.nil?
doc['v']
end
end
@@ -48,8 +50,12 @@ def update(key, updates)
@collection.update criteria(key), updates, @update_options
end
+ def remove(key)
+ @collection.remove criteria(key)
+ end
+
def criteria(key)
- {:_id => key}
+ {:_id => key.to_s}
end
end
end
@@ -17,37 +17,37 @@ def initialize(collection, options = {})
end
def read(key)
- source[key]
+ source[key.to_s]
end
def write(key, value)
- @collection.update @criteria, {'$set' => {key => value}}, @mongo_options
- @source[key] = value
+ @collection.update @criteria, {'$set' => {key.to_s => value}}, @mongo_options
+ @source[key.to_s] = value
end
def delete(key)
- @collection.update @criteria, {'$unset' => {key => 1}}, @mongo_options
- @source.delete key
+ @collection.update @criteria, {'$unset' => {key.to_s => 1}}, @mongo_options
+ @source.delete key.to_s
end
def set_members(key)
- members = source.fetch(key) { @source[key] = Set.new }
+ members = source.fetch(key.to_s) { @source[key.to_s] = Set.new }
if members.is_a?(Array)
- @source[key] = members.to_set
+ @source[key.to_s] = members.to_set
else
members
end
end
def set_add(key, value)
- @collection.update @criteria, {'$addToSet' => {key => value}}, @mongo_options
- set_members(key).add(value)
+ @collection.update @criteria, {'$addToSet' => {key.to_s => value}}, @mongo_options
+ set_members(key.to_s).add(value)
end
def set_delete(key, value)
- @collection.update @criteria, {'$pull' => {key => value}}, @mongo_options
- set_members(key).delete(value)
+ @collection.update @criteria, {'$pull' => {key.to_s => value}}, @mongo_options
+ set_members(key.to_s).delete(value)
end
def clear
@@ -15,7 +15,7 @@
def read_key(key)
if (doc = collection.find_one(criteria))
- value = doc[key]
+ value = doc[key.to_s]
if value.is_a?(::Array)
value = value.to_set
@@ -31,7 +31,7 @@ def write_key(key, value)
end
options = {:upsert => true}
- updates = {'$set' => {key => value}}
+ updates = {'$set' => {key.to_s => value}}
collection.update criteria, updates, options
end
@@ -13,7 +13,7 @@
end
def read_key(key)
- if (doc = collection.find_one(:_id => key))
+ if (doc = collection.find_one(:_id => key.to_s))
value = doc['v']
if value.is_a?(::Array)
@@ -29,7 +29,7 @@ def write_key(key, value)
value = value.to_a
end
- criteria = {:_id => key}
+ criteria = {:_id => key.to_s}
updates = {'$set' => {'v' => value}}
options = {:upsert => true}
collection.update criteria, updates, options

0 comments on commit beac52e

Please sign in to comment.