lib/ohm.rb in ohm-2.0.0.alpha2 vs lib/ohm.rb in ohm-2.0.0.alpha3
- old
+ new
@@ -836,11 +836,11 @@
#
# Note: You can't use the set until you save the model. If you try
# to do it, you'll receive an Ohm::MissingID error.
#
def self.set(name, model)
- collections << name unless collections.include?(name)
+ track(name)
define_method name do
model = Utils.const(self.class, model)
Ohm::MutableSet.new(key[name], model.key, model)
@@ -866,11 +866,11 @@
#
# Note: You can't use the list until you save the model. If you try
# to do it, you'll receive an Ohm::MissingID error.
#
def self.list(name, model)
- collections << name unless collections.include?(name)
+ track(name)
define_method name do
model = Utils.const(self.class, model)
Ohm::List.new(key[name], model.key, model)
@@ -1031,10 +1031,15 @@
redis.call("HGET", key[:counters], name).to_i
end
end
+ # Keep track of `key[name]` and remove when deleting the object.
+ def self.track(name)
+ tracked << name unless tracked.include?(name)
+ end
+
# An Ohm::Set wrapper for Model.key[:all].
def self.all
Set.new(key[:all], key, self)
end
@@ -1277,11 +1282,11 @@
{ "name" => model.name,
"id" => id,
"key" => key
}.to_msgpack,
uniques.to_msgpack,
- model.collections.to_msgpack
+ model.tracked.to_msgpack
)
return self
end
@@ -1342,11 +1347,11 @@
def self.counters
@counters ||= []
end
- def self.collections
- @collections ||= []
+ def self.tracked
+ @tracked ||= []
end
def self.attributes
@attributes ||= []
end