Sha256: 2109c73a279d504804e39df87c8b7d7d00c6b421d6a6e2e14209d92e4eb48226

Contents?: true

Size: 792 Bytes

Versions: 3

Compression:

Stored size: 792 Bytes

Contents

module Mongoid
  module Report

    # Split the queries into threads.
    Batches = Struct.new(:settings, :conditions) do
      DEFAULT_THREAD_POOL_SIZE = 5

      def initialize(settings = {}, conditions = {})
        if settings.nil? || settings.empty?
          settings = { 'pool_size' => DEFAULT_THREAD_POOL_SIZE }
        end

        super(settings, conditions)
      end

      def field
        conditions.keys[0]
      end

      def range
        conditions.values[0]
      end

      def map
        range.each_slice(size.ceil).map do |r|
          yield r
        end
      end

      def size
        range.count.to_f / settings['pool_size'].to_f
      end

      def present?
        settings['pool_size'].present? &&
          conditions.present?
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mongoid-report-0.2.2 lib/mongoid/report/batches.rb
mongoid-report-0.2.1 lib/mongoid/report/batches.rb
mongoid-report-0.2.0 lib/mongoid/report/batches.rb