lib/ohm.rb in ohm-1.3.2 vs lib/ohm.rb in ohm-1.4.0

- old
+ new

@@ -147,11 +147,11 @@ if block_given? ids.each_slice(1000) do |slice| fetch(slice).each { |e| yield(e) } end else - Enumerator.new(self, :each) + to_enum end end # Fetch the data from Redis in one go. def to_a @@ -465,10 +465,24 @@ # def except(dict) MultiSet.new(namespace, model, key).except(dict) end + # Perform an intersection between the existent set and + # the new set created by the union of the passed filters. + # + # Example: + # + # set = User.find(:status => "active") + # set.combine(:name => ["John", "Jane"]) + # + # # The result will include all users with active status + # # and with names "John" or "Jane". + def combine(dict) + MultiSet.new(namespace, model, key).combine(dict) + end + # Do a union to the existing set using any number of filters. # # Example: # # set = User.find(:name => "John") @@ -596,14 +610,30 @@ # # You can also do it in one line. # User.find(:name => "John").except(:country => "US") # def except(dict) MultiSet.new( - namespace, model, Command[:sdiffstore, command, intersected(dict)] + namespace, model, Command[:sdiffstore, command, unioned(dict)] ) end + # Perform an intersection between the existent set and + # the new set created by the union of the passed filters. + # + # Example: + # + # set = User.find(:status => "active") + # set.combine(:name => ["John", "Jane"]) + # + # # The result will include all users with active status + # # and with names "John" or "Jane". + def combine(dict) + MultiSet.new( + namespace, model, Command[:sinterstore, command, unioned(dict)] + ) + end + # Do a union to the existing set using any number of filters. # # Example: # # set = User.find(:name => "John") @@ -623,9 +653,14 @@ model.db end def intersected(dict) Command[:sinterstore, *model.filters(dict)] + end + + + def unioned(dict) + Command[:sunionstore, *model.filters(dict)] end def execute # namespace[:tmp] is where all the temp keys should be stored in. # db will be where all the commands are executed against.