Sha256: 03d433e62fc61e163c45d61591c59337053c36084bd72239b4bb415b1f5e0e9c

Contents?: true

Size: 479 Bytes

Versions: 1

Compression:

Stored size: 479 Bytes

Contents

require 'active_support/concern'

module Journey::Resource::BatchWhere
  extend ActiveSupport::Concern

  included do

    def self.batch_where(clauses, batch_size=100)

      total_count = count(clauses)
      query_count = (total_count / batch_size.to_f).ceil.to_i

      (0 ... query_count).to_a.map do |batch_index|

        where_multiple clauses.merge({
          limit: batch_size,
          skip: batch_index * batch_size
        })

      end.flatten
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
embark-journey-0.1.3 lib/journey/resource/batch_where.rb