Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added a where method.

  • Loading branch information...
commit 7be6f0634b483a9ae2bfe9d61dbc30a9e6c72dd3 1 parent d5c06b8
@dhruvasagar dhruvasagar authored
Showing with 15 additions and 1 deletion.
  1. +1 −0  .gitignore
  2. +14 −1 lib/supermodel/base.rb
View
1  .gitignore
@@ -4,3 +4,4 @@ redis_test.rb
pkg
lib/supermodel/cassandra.rb
*.gem
+tags
View
15 lib/supermodel/base.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.