ar-octopus 0.10.0 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 962dc9c9117e08008c637c759626480b47566338
4
- data.tar.gz: 8661fb69b2f9fd24df265827eabbc5ee4aa623ce
3
+ metadata.gz: 10312fc71268bf4330c9a6c49038d5b1b3dab35a
4
+ data.tar.gz: 3aaf8fd301f7a018b9df3fbc247b3080f624ed52
5
5
  SHA512:
6
- metadata.gz: f6091ea4584d2c031076b6ea0f4fc06abd9a10c2ed4d88762711d4854c8524c5172bab6081e50bc2a73c8ccf67dc68aeba8d91cdf179cfdc9aa7b77dbff37924
7
- data.tar.gz: 96109ec7506bed3e1cd898e2efb1174006d18ca35ee538dbf5e1912fc3d4465188dd7110884ffaff17c2c9fefe126c726e415201e8423e2e957e1dbbaf7bd378
6
+ metadata.gz: 79dd6e2fedf56d5bb00ecf8afef6f0749fd842c8b7c9f1bb4735a059a6706d373623e49b43c1f47606808a4c6b90e40b5640f29053d0ee4f7de25a043ff175a2
7
+ data.tar.gz: 0400e3053af09d3b591a4992967787fb4957a48148b0a8fa3b290b8b8f7201519f72361a45acd49f366323b821463a1039059b186baf5ac38653b26649ebd87c
@@ -26,9 +26,18 @@ module Octopus
26
26
  end + [:each, :map, :index_by]
27
27
  # `find { ... }` etc. should run_on_shard, `find(id)` should be sent to relation
28
28
  ENUM_WITH_BLOCK_METHODS = [:find, :select, :none?, :any?, :one?, :many?, :sum]
29
+ BATCH_METHODS = [:find_each, :find_in_batches, :in_batches]
29
30
 
30
31
  def method_missing(method, *args, &block)
31
- if ENUM_METHODS.include?(method) || block && ENUM_WITH_BLOCK_METHODS.include?(method)
32
+ if !block && BATCH_METHODS.include?(method)
33
+ ::Enumerator.new do |yielder|
34
+ run_on_shard do
35
+ @ar_relation.public_send(method, *args) do |batch_item|
36
+ yielder << batch_item
37
+ end
38
+ end
39
+ end
40
+ elsif ENUM_METHODS.include?(method) || block && ENUM_WITH_BLOCK_METHODS.include?(method)
32
41
  run_on_shard { @ar_relation.to_a }.public_send(method, *args, &block)
33
42
  elsif block
34
43
  @ar_relation.public_send(method, *args, &block)
@@ -1,3 +1,3 @@
1
1
  module Octopus
2
- VERSION = '0.10.0'
2
+ VERSION = '0.10.1'
3
3
  end
@@ -522,7 +522,7 @@ describe Octopus::Model do
522
522
  @user3 = User.using(:brazil).create!(:name => 'User3')
523
523
  end
524
524
 
525
- it "#find_each should work" do
525
+ it "#find_each should work with a block" do
526
526
  result_array = []
527
527
 
528
528
  User.using(:brazil).where("name is not NULL").find_each do |user|
@@ -532,7 +532,27 @@ describe Octopus::Model do
532
532
  expect(result_array).to eq([@user1, @user2, @user3])
533
533
  end
534
534
 
535
- it "#find_in_batches, should work" do
535
+ it "#find_each should work as an enumerator" do
536
+ result_array = []
537
+
538
+ User.using(:brazil).where("name is not NULL").find_each.each do |user|
539
+ result_array << user
540
+ end
541
+
542
+ expect(result_array).to eq([@user1, @user2, @user3])
543
+ end
544
+
545
+ it "#find_each should work as a lazy enumerator" do
546
+ result_array = []
547
+
548
+ User.using(:brazil).where("name is not NULL").find_each.lazy.each do |user|
549
+ result_array << user
550
+ end
551
+
552
+ expect(result_array).to eq([@user1, @user2, @user3])
553
+ end
554
+
555
+ it "#find_in_batches should work with a block" do
536
556
  result_array = []
537
557
 
538
558
  User.using(:brazil).where("name is not NULL").find_in_batches(batch_size: 1) do |user|
@@ -541,6 +561,26 @@ describe Octopus::Model do
541
561
 
542
562
  expect(result_array).to eq([[@user1], [@user2], [@user3]])
543
563
  end
564
+
565
+ it "#find_in_batches should work as an enumerator" do
566
+ result_array = []
567
+
568
+ User.using(:brazil).where("name is not NULL").find_in_batches(batch_size: 1).each do |user|
569
+ result_array << user
570
+ end
571
+
572
+ expect(result_array).to eq([[@user1], [@user2], [@user3]])
573
+ end
574
+
575
+ it "#find_in_batches should work as a lazy enumerator" do
576
+ result_array = []
577
+
578
+ User.using(:brazil).where("name is not NULL").find_in_batches(batch_size: 1).lazy.each do |user|
579
+ result_array << user
580
+ end
581
+
582
+ expect(result_array).to eq([[@user1], [@user2], [@user3]])
583
+ end
544
584
  end
545
585
 
546
586
  describe 'deleting a record' do
@@ -58,10 +58,18 @@ describe Octopus::RelationProxy do
58
58
  end
59
59
  end
60
60
 
61
- it "can deliver methods in ActiveRecord::Batches correctly" do
61
+ it "can deliver methods in ActiveRecord::Batches correctly when given a block" do
62
62
  expect { @relation.find_each(&:inspect) }.not_to raise_error
63
63
  end
64
64
 
65
+ it "can deliver methods in ActiveRecord::Batches correctly as an enumerator" do
66
+ expect { @relation.find_each.each(&:inspect) }.not_to raise_error
67
+ end
68
+
69
+ it "can deliver methods in ActiveRecord::Batches correctly as a lazy enumerator" do
70
+ expect { @relation.find_each.lazy.each(&:inspect) }.not_to raise_error
71
+ end
72
+
65
73
  context 'under Rails 4' do
66
74
  it 'is an Octopus::RelationProxy' do
67
75
  expect{@relation.ar_relation}.not_to raise_error
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar-octopus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thiago Pradi