Sha256: dac49f9c20d7a844c76f92dcc5b50944945faa8d0efda40b00eb2533ad7b42a0

Contents?: true

Size: 686 Bytes

Versions: 10

Compression:

Stored size: 686 Bytes

Contents

module CassandraObject
  module FindEach
    extend ActiveSupport::Concern

    module ClassMethods
      def find_each(options={})
        find_in_batches(options) do |records|
          records.each { |record| yield record }
        end
        nil
      end

      def find_in_batches(options={})
        start = options[:start] || ''
        finish = options[:finish] || ''
        batch_size = options[:batch_size] || 100

        records = all(start..finish, limit: batch_size)
        while records.any?
          yield records
          records = all(records.last.key.to_s..finish, limit: batch_size+1)
          records.shift
        end
        nil
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
gotime-cassandra_object-0.9.1 lib/cassandra_object/find_each.rb
gotime-cassandra_object-0.9.0 lib/cassandra_object/find_each.rb
gotime-cassandra_object-0.8.7 lib/cassandra_object/find_each.rb
gotime-cassandra_object-0.8.6 lib/cassandra_object/find_each.rb
gotime-cassandra_object-0.8.5 lib/cassandra_object/find_each.rb
gotime-cassandra_object-0.8.4 lib/cassandra_object/find_each.rb
gotime-cassandra_object-0.8.3 lib/cassandra_object/find_each.rb
gotime-cassandra_object-0.8.2 lib/cassandra_object/find_each.rb
gotime-cassandra_object-0.8.1 lib/cassandra_object/find_each.rb
gotime-cassandra_object-0.8.0 lib/cassandra_object/find_each.rb