lib/ohm.rb in ohm-0.0.33 vs lib/ohm.rb in ohm-0.0.34
- old
+ new
@@ -6,10 +6,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.34"
# Provides access to the Redis database. This is shared accross all models and instances.
def redis
threaded[:redis] ||= connection(*options)
end
@@ -193,11 +194,11 @@
private
# Apply a redis operation on a collection of sets.
def apply(operation, hash, glue)
target = key.volatile.group(glue).append(*keys(hash))
- model.db.send(operation, target, *target.parts)
+ model.db.send(operation, target, *target.sub_keys)
Set.new(target, model)
end
# Transform a hash of attribute/values into an array of keys.
def keys(hash)
@@ -212,9 +213,25 @@
end
end
class List < Collection
Raw = Ohm::List
+
+ def shift
+ if id = raw.shift
+ model[id]
+ end
+ end
+
+ def pop
+ if id = raw.pop
+ model[id]
+ end
+ end
+
+ def unshift(model)
+ raw.unshift(model.id)
+ end
def inspect
"#<List (#{model}): #{all.inspect}>"
end
end