Module: DataMapper::ChunkedQuery::Mixin

Defined in:
lib/dm-chunked_query/mixin.rb

Instance Method Summary collapse

Instance Method Details

#batch(per_batch) {|resource| ... } ⇒ Chunks

Reads in records in batches and processes them.

Parameters:

  • per_batch (Integer)

    The number of resources per-batch.

Yields:

  • (resource)

    The given block will be passed each resource from each batch of resources.

Yield Parameters:

  • resource (DataMapper::Resource)

    A resource from the batch.

Returns:

  • (Chunks)

    The abstract collection of chunks from the query.

See Also:

Since:

  • 0.3.0



78
79
80
# File 'lib/dm-chunked_query/mixin.rb', line 78

def batch(per_batch,&block)
  each_chunk(per_batch) { |chunk| chunk.each(&block) }
end

#chunks(per_chunk) ⇒ Chunks

Allows chunked access to the resources from a query.

Parameters:

  • per_chunk (Integer)

    The number of resources per-chunk.

Returns:

  • (Chunks)

    The abstract collection of chunks from the query.



15
16
17
# File 'lib/dm-chunked_query/mixin.rb', line 15

def chunks(per_chunk)
  Chunks.new(self,per_chunk)
end

#chunks_of(per_chunk) ⇒ Object

See Also:



22
23
24
# File 'lib/dm-chunked_query/mixin.rb', line 22

def chunks_of(per_chunk)
  chunks(per_chunk)
end

#each_chunk(per_chunk) {|chunk| ... } ⇒ Chunks

Enumerate over every chunk.

Parameters:

  • per_chunk (Integer)

    The number of resources per-chunk.

Yields:

  • (chunk)

    A chunk of resources within the query.

Yield Parameters:

  • chunk (DataMapper::Collection)

    A collection of resources that makes up the chunk.

Returns:

  • (Chunks)

    The abstract collection of chunks from the query.

See Also:

Since:

  • 0.2.0



45
46
47
# File 'lib/dm-chunked_query/mixin.rb', line 45

def each_chunk(per_chunk,&block)
  chunks(per_chunk).each(&block)
end

#each_slice(per_chunk, &block) ⇒ Object

See Also:

Since:

  • 0.3.0



54
55
56
# File 'lib/dm-chunked_query/mixin.rb', line 54

def each_slice(per_chunk,&block)
  each_chunk(per_chunk,&block)
end