mongomodel 0.2.16 → 0.2.17
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mongomodel/concerns/associations/has_many_by_foreign_key.rb +1 -1
- data/lib/mongomodel/document/scopes.rb +1 -1
- data/lib/mongomodel/support/scope.rb +2 -1
- data/lib/mongomodel/support/scope/batches.rb +15 -0
- data/lib/mongomodel/version.rb +1 -1
- data/spec/mongomodel/support/scope_spec.rb +14 -0
- metadata +5 -4
@@ -111,7 +111,7 @@ module MongoModel
|
|
111
111
|
|
112
112
|
class Proxy < Base::Proxy
|
113
113
|
# Pass these methods to the scope rather than the Array target
|
114
|
-
OVERRIDE_METHODS = [ :find, :first, :last, :count ]
|
114
|
+
OVERRIDE_METHODS = [ :find, :first, :last, :count, :paginate ]
|
115
115
|
|
116
116
|
delegate :ensure_class, :to => :association
|
117
117
|
|
@@ -13,7 +13,7 @@ module MongoModel
|
|
13
13
|
module ClassMethods
|
14
14
|
delegate :find, :first, :last, :all, :exists?, :count, :to => :scoped
|
15
15
|
delegate :update, :update_all, :delete, :delete_all, :destroy, :destroy_all, :to => :scoped
|
16
|
-
delegate :select, :order, :where, :limit, :offset, :from, :paginate, :to => :scoped
|
16
|
+
delegate :select, :order, :where, :limit, :offset, :from, :paginate, :in_batches, :to => :scoped
|
17
17
|
|
18
18
|
def unscoped
|
19
19
|
@unscoped ||= MongoModel::Scope.new(self)
|
@@ -10,8 +10,9 @@ module MongoModel
|
|
10
10
|
autoload :FinderMethods, 'mongomodel/support/scope/finder_methods'
|
11
11
|
autoload :DynamicFinders, 'mongomodel/support/scope/dynamic_finders'
|
12
12
|
autoload :Pagination, 'mongomodel/support/scope/pagination'
|
13
|
+
autoload :Batches, 'mongomodel/support/scope/batches'
|
13
14
|
|
14
|
-
include Pagination, DynamicFinders, FinderMethods, QueryMethods, SpawnMethods
|
15
|
+
include Batches, Pagination, DynamicFinders, FinderMethods, QueryMethods, SpawnMethods
|
15
16
|
|
16
17
|
delegate :inspect, :as_json, :to => :to_a
|
17
18
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module MongoModel
|
2
|
+
class Scope
|
3
|
+
module Batches
|
4
|
+
def in_batches(batch_size=1000)
|
5
|
+
offset = 0
|
6
|
+
|
7
|
+
begin
|
8
|
+
documents = offset(offset).limit(batch_size).all
|
9
|
+
yield documents if block_given? && !documents.empty?
|
10
|
+
offset += batch_size
|
11
|
+
end until documents.size < batch_size
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/mongomodel/version.rb
CHANGED
@@ -775,6 +775,20 @@ module MongoModel
|
|
775
775
|
paginator.total_entries.should == 57
|
776
776
|
end
|
777
777
|
end
|
778
|
+
|
779
|
+
describe "#in_batches" do
|
780
|
+
it "should yield documents in groups of given size" do
|
781
|
+
model.should_find(finder_options.merge(:offset => 0, :limit => 3), posts.first(3))
|
782
|
+
model.should_find(finder_options.merge(:offset => 3, :limit => 3), posts.last(2))
|
783
|
+
|
784
|
+
expected_size = 3
|
785
|
+
|
786
|
+
subject.in_batches(3) do |docs|
|
787
|
+
docs.size.should == expected_size
|
788
|
+
expected_size = 2
|
789
|
+
end
|
790
|
+
end
|
791
|
+
end
|
778
792
|
end
|
779
793
|
|
780
794
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongomodel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 53
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 17
|
10
|
+
version: 0.2.17
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sam Pohlenz
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-07 00:00:00 +10:30
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -188,6 +188,7 @@ files:
|
|
188
188
|
- lib/mongomodel/support/mongo_order.rb
|
189
189
|
- lib/mongomodel/support/reference.rb
|
190
190
|
- lib/mongomodel/support/scope.rb
|
191
|
+
- lib/mongomodel/support/scope/batches.rb
|
191
192
|
- lib/mongomodel/support/scope/dynamic_finders.rb
|
192
193
|
- lib/mongomodel/support/scope/finder_methods.rb
|
193
194
|
- lib/mongomodel/support/scope/pagination.rb
|