Permalink
Browse files

Added a where method.

  • Loading branch information...
1 parent d5c06b8 commit 7be6f0634b483a9ae2bfe9d61dbc30a9e6c72dd3 @dhruvasagar dhruvasagar committed Apr 19, 2013
Showing with 15 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +14 −1 lib/supermodel/base.rb
View
@@ -4,3 +4,4 @@ redis_test.rb
pkg
lib/supermodel/cassandra.rb
*.gem
+tags
@@ -54,6 +54,19 @@ def last
item = records.values[-1]
item && item.dup
end
+
+ def where(options)
+ items = records.values.select do |r|
+ options.all? do |k, v|
+ if v.is_a?(Enumerable)
+ v.include?(r.send(k))
+ else
+ r.send(k) == v
+ end
+ end
+ end
+ collection.new(items.deep_dup)
+ end
def exists?(id)
records.has_key?(id)
@@ -310,4 +323,4 @@ class Base
include Dirty, Observing, Callbacks, Validations
include Association::Model
end
-end
+end

0 comments on commit 7be6f06

Please sign in to comment.