lib/ohm.rb in ohm-0.0.36 vs lib/ohm.rb in ohm-0.0.37
- old
+ new
@@ -7,11 +7,11 @@
require File.join(File.dirname(__FILE__), "ohm", "compat-1.8.6")
require File.join(File.dirname(__FILE__), "ohm", "key")
require File.join(File.dirname(__FILE__), "ohm", "collection")
module Ohm
- VERSION = "0.0.36"
+ VERSION = "0.0.37"
# Provides access to the Redis database. This is shared accross all models and instances.
def redis
threaded[:redis] ||= connection(*options)
end
@@ -288,11 +288,11 @@
# @overload assert_unique :name
# Validates that the name attribute is unique.
# @overload assert_unique [:street, :city]
# Validates that the :street and :city pair is unique.
def assert_unique(attrs)
- result = db.sinter(*Array(attrs).map { |att| index_key_for(att, send(att)) })
+ result = db.sinter(*Array(attrs).map { |att| index_key_for(att, send(att)) }) || []
assert result.empty? || !new? && result.include?(id.to_s), [attrs, :not_unique]
end
end
include Validations
@@ -784,13 +784,14 @@
db.sadd(index, id)
db.sadd(key(:_indices), index)
end
def delete_from_indices
- db.smembers(key(:_indices)).each do |index|
+ (db.smembers(key(:_indices)) || []).each do |index|
db.srem(index, id)
- db.srem(key(:_indices), index)
end
+
+ db.del(key(:_indices))
end
def read_local(att)
@_attributes[att]
end