dm-chunked_query 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog.md +6 -0
- data/README.md +7 -1
- data/gemspec.yml +1 -1
- data/lib/dm-chunked_query/mixin.rb +33 -0
- data/spec/chunked_query_spec.rb +20 -2
- metadata +3 -3
data/ChangeLog.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
### 0.3.0 / 2011-05-16
|
2
|
+
|
3
|
+
* Added {DataMapper::ChunkedQuery::Mixin#each_slice} which calls
|
4
|
+
{DataMapper::ChunkedQuery::Mixin#each_chunk}.
|
5
|
+
* Added {DataMapper::ChunkedQuery::Mixin#batch}.
|
6
|
+
|
1
7
|
### 0.2.1 / 2011-05-02
|
2
8
|
|
3
9
|
* Fixed a typo in {DataMapper::ChunkedQuery::Mixin#each_chunk}.
|
data/README.md
CHANGED
@@ -22,7 +22,7 @@ Enumerate over all chunks, 20 resources per-chunk:
|
|
22
22
|
|
23
23
|
require 'dm-chunked_query'
|
24
24
|
|
25
|
-
MyModel.each_chunk(20)
|
25
|
+
MyModel.each_chunk(20) do |chunk|
|
26
26
|
chunk.each do |resource|
|
27
27
|
# ...
|
28
28
|
end
|
@@ -32,6 +32,12 @@ Get the 5th chunk, containing 10 resources:
|
|
32
32
|
|
33
33
|
MyModel.all(:foo => 'bar').chunks(10)[5]
|
34
34
|
|
35
|
+
Process records in batches:
|
36
|
+
|
37
|
+
MyModel.batch(100) do |resource|
|
38
|
+
# ...
|
39
|
+
end
|
40
|
+
|
35
41
|
## Requirements
|
36
42
|
|
37
43
|
* [dm-core](http://github.com/datamapper/dm-core#readme) ~> 1.0
|
data/gemspec.yml
CHANGED
@@ -45,6 +45,39 @@ module DataMapper
|
|
45
45
|
def each_chunk(per_chunk,&block)
|
46
46
|
chunks(per_chunk).each(&block)
|
47
47
|
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# @see each_chunk
|
51
|
+
#
|
52
|
+
# @since 0.3.0
|
53
|
+
#
|
54
|
+
def each_slice(per_chunk,&block)
|
55
|
+
each_chunk(per_chunk,&block)
|
56
|
+
end
|
57
|
+
|
58
|
+
#
|
59
|
+
# Reads in records in batches and processes them.
|
60
|
+
#
|
61
|
+
# @param [Integer] per_batch
|
62
|
+
# The number of resources per-batch.
|
63
|
+
#
|
64
|
+
# @yield [resource]
|
65
|
+
# The given block will be passed each resource from each batch
|
66
|
+
# of resources.
|
67
|
+
#
|
68
|
+
# @yieldparam [DataMapper::Resource] resource
|
69
|
+
# A resource from the batch.
|
70
|
+
#
|
71
|
+
# @return [Chunks]
|
72
|
+
# The abstract collection of chunks from the query.
|
73
|
+
#
|
74
|
+
# @see #each_chunk
|
75
|
+
#
|
76
|
+
# @since 0.3.0
|
77
|
+
#
|
78
|
+
def batch(per_batch,&block)
|
79
|
+
each_chunk(per_batch) { |chunk| chunk.each(&block) }
|
80
|
+
end
|
48
81
|
end
|
49
82
|
end
|
50
83
|
end
|
data/spec/chunked_query_spec.rb
CHANGED
@@ -1,11 +1,29 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DataMapper::ChunkedQuery do
|
4
|
+
subject { TestModel }
|
5
|
+
|
4
6
|
it "should allow chunked queries directly from Models" do
|
5
|
-
|
7
|
+
subject.chunks(1).length.should == 100
|
6
8
|
end
|
7
9
|
|
8
10
|
it "should allow chunked queries from other queries" do
|
9
|
-
|
11
|
+
subject.all(:number.lte => 50).chunks(1).length.should == 50
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should allow iterating over every resource" do
|
15
|
+
count = 0
|
16
|
+
|
17
|
+
subject.each_chunk(2) { |chunk| count += chunk.length }
|
18
|
+
|
19
|
+
count.should == 100
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should allow processing records in batch" do
|
23
|
+
count = 0
|
24
|
+
|
25
|
+
subject.batch(2) { |resource| count += 1 }
|
26
|
+
|
27
|
+
count.should == 100
|
10
28
|
end
|
11
29
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: dm-chunked_query
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Postmodern
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-16 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: dm-core
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
requirements: []
|
119
119
|
|
120
120
|
rubyforge_project: dm-chunked_query
|
121
|
-
rubygems_version: 1.
|
121
|
+
rubygems_version: 1.8.1
|
122
122
|
signing_key:
|
123
123
|
specification_version: 3
|
124
124
|
summary: Allows performing chunked queries with DataMapper.
|