lib/ohm.rb in ohm-0.0.19 vs lib/ohm.rb in ohm-0.0.20

- old
+ new

@@ -227,12 +227,19 @@ # Returns an intersection with the sets generated from the passed hash. # # @see Ohm::Model.filter # @yield [results] Results of the filtering. Beware that the set of results is deleted from Redis when the block ends. # @example + # Event.filter(public: true) do |filter_results| + # @events = filter_results.all + # end + # + # # You can also combine search and filter # Event.search(day: "2009-09-11") do |search_results| - # events = search_results.all + # search_results.filter(public: true) do |filter_results| + # @events = filter_results.all + # end # end def filter(hash, &block) apply(:sinterstore, keys(hash).push(key), &block) end @@ -240,13 +247,11 @@ # # @see Ohm::Model.search # @yield [results] Results of the search. Beware that the set of results is deleted from Redis when the block ends. # @example # Event.search(day: "2009-09-11") do |search_results| - # search_results.filter(public: true) do |filter_results| - # events = filter_results.all - # end + # events = search_results.all # end def search(hash, &block) apply(:sunionstore, keys(hash), &block) end @@ -255,11 +260,11 @@ end # Apply a redis operation on a collection of sets. Note that # the resulting set is removed inmediatly after use. def apply(operation, source, &block) - target = source.join(operation) + target = source.join(operation.to_s) db.send(operation, target, *source) set = self.class.new(db, target, model) block.call(set) set.delete! end @@ -534,10 +539,10 @@ def indices self.class.indices end def ==(other) - other.key == key + other.kind_of?(self.class) && other.key == key rescue ModelIsNew false end # Lock the object before ejecuting the block, and release it once the block is done.