the_grid 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmUzMzViNTAwMmM5MjlmNGVjOWY2OGY1N2E3ZmVhMzBiYTA5NDhlOA==
4
+ NGE5YjY3ZGZiZjJjOWUxMjBlMDlkMGNmYzRlMGQ0ODEzMTYyODc3Yg==
5
5
  data.tar.gz: !binary |-
6
- YWY0N2ZlYzE4N2U1ZWUwMjhkOTJjNWUzNjE3OTY0ZDY4ODlkNTNkOQ==
6
+ ZWVmMDM4YTAxOGM3N2Y1NmI2ZmI5YTY0ZTcxMDZhMmQ4MTc0NmRiMQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZWU3NzRhMGNjM2ZiMzQwMGVjMTAyNTdhMTQyZDE2MDM3YzQ1ZjNhODhhZDc5
10
- ZGZiZDdmNGM1ZmRlMDY5ZjU1M2U1ZDdkZjE2MTQ5YjZmMjc3MDE2MGJiYmRk
11
- N2ZmOGVhN2YwODZjOTFiNDBiOTNiYmRjNTIwMTBmNzQ4NmJjYWU=
9
+ YjEwYWU3Y2E5MGE5YmYwYWZmYmE5MmMyY2YwNjVhNjYxOTBiYWE2NmYwZDk4
10
+ NjY3MzY5Y2Y4YmU4M2UxNjRhMmNjNDE5NzVlMDNlOTU0YzdlMTgxOWU4Y2Ni
11
+ Njg4YjUwNjA2NThmNjgwNDYxNjMyOWY5MjI4NmU5Y2Q5MDI3ZGI=
12
12
  data.tar.gz: !binary |-
13
- ZmE5ZDRkODVjMjMxMzI1MDRkNDQzMzkwYjU4MTZlZWIxMWFjYTBiMjAxYzRh
14
- ODgxZmU3ZmJlOGMxZWI3ZjE5ODc5MDJhMzY5ZGIxNDU0MTAxZDE5Nzk5ZDVm
15
- ZDdjYmMzNmI5NDY1MzJmMzQ5MDU5MTk2Zjg4ZWRjOTUwZDVjOTU=
13
+ YTI3NzIwMTc2MmJiNzY5YTQzZmVjZjU0ODVjYmM0NGQ5N2NmNGEwNDljZWYw
14
+ MGU4NzhhZmQ5NjAwZjIyMzc4YWY4MDMxZjUyMDllMGQ2MGE1NmMzZDIxYzQx
15
+ ZTNjMGY3YzQ2Y2I0Y2FjYzM2MWFkNDU1OGIxMmRkNGI0OWE5MGQ=
@@ -6,6 +6,7 @@ module TheGrid
6
6
  {}.tap do |o|
7
7
  o[:page] = params[:page].to_i
8
8
  o[:page] = 1 if o[:page] <= 0
9
+ o[:size] = params[:size]
9
10
 
10
11
  o[:per_page] = params[:per_page].to_i
11
12
  o[:per_page] = self.class.default_per_page if o[:per_page] <= 0
@@ -18,7 +19,8 @@ module TheGrid
18
19
 
19
20
  def calculate_max_page_for(relation, params)
20
21
  params = configure(relation, params)
21
- (relation.except(:limit, :offset).count / params[:per_page].to_f).ceil
22
+ total_count = params[:size].present? ? params[:size] : relation.except(:limit, :offset, :includes).count
23
+ (total_count / params[:per_page].to_f).ceil
22
24
  end
23
25
 
24
26
  def contextualize(relation, params)
@@ -26,4 +28,4 @@ module TheGrid
26
28
  end
27
29
 
28
30
  end
29
- end
31
+ end
@@ -13,7 +13,7 @@ module TheGrid
13
13
 
14
14
  def assemble_with(params)
15
15
  options = params.merge context.params
16
- api.compose!(options.merge :per_page => BATCH_SIZE) if api.relation.respond_to?(:except)
16
+ api.compose!(options.merge :per_page => BATCH_SIZE) if api.relation.respond_to?(:connection)
17
17
  generate_csv_with(options)
18
18
  end
19
19
 
@@ -25,14 +25,15 @@ module TheGrid
25
25
  api.relation.kind_of?(Array) ? put_data_to(csv) : put_relation_to(csv)
26
26
  end
27
27
  end
28
-
28
+
29
29
  def put_data_to(csv)
30
30
  put_records_to(csv, api.relation)
31
31
  end
32
32
 
33
33
  def put_relation_to(csv)
34
- (1..api.options[:max_page]).each do |page|
35
- relation = api.run_command!(:paginate, :page => page, :per_page => BATCH_SIZE)
34
+ pages = api.options[:max_page]
35
+ (1..pages).each do |page|
36
+ relation = api.run_command!(:paginate, :page => page, :per_page => BATCH_SIZE, :size => pages * BATCH_SIZE)
36
37
  put_records_to(csv, relation)
37
38
  end
38
39
  end
@@ -1,3 +1,3 @@
1
1
  module TheGrid
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
3
3
  end
@@ -35,10 +35,15 @@ describe TheGrid::Api::Command::Paginate do
35
35
  it "should respect specified per_page option" do
36
36
  subject.calculate_max_page_for(relation, :per_page => 15).should eql 2
37
37
  end
38
+
39
+ it "does not count rows if size options is present" do
40
+ relation.should_not_receive(:count)
41
+ subject.calculate_max_page_for(relation, :per_page => 15, :page => 1, :size => 100)
42
+ end
38
43
  end
39
44
 
40
45
  it "calculates max page when prepares context" do
41
46
  subject.contextualize(relation, :page => 1, :per_page => 15).fetch(:max_page).should eql 2
42
47
  end
43
48
 
44
- end
49
+ end
@@ -5,7 +5,8 @@ describe TheGrid::Builder::Csv do
5
5
  subject{ TheGrid::Builder::Csv.new(relation, build_context) }
6
6
 
7
7
  include_examples "for Grid View Builder"
8
- before(:each) { subject.api.stub(:compose!){ subject.api.options[:max_page] = 1 } }
8
+ before(:each) { subject.api.stub(:compose!) }
9
+ before(:each) { subject.api.options[:max_page] = 1 }
9
10
 
10
11
  let(:relation) { double.as_null_object }
11
12
  let(:record) {{ :id => 1, :name => "Name", :status => "Active", :text => "Text" }}
@@ -23,7 +24,7 @@ describe TheGrid::Builder::Csv do
23
24
  end
24
25
 
25
26
  it "generates csv records in batches" do
26
- subject.api.should_receive(:run_command!).with(:paginate, :page => 1, :per_page => params[:per_page])
27
+ subject.api.should_receive(:run_command!).with(:paginate, :page => 1, :per_page => params[:per_page], :size => subject.api.options[:max_page] * params[:per_page])
27
28
  subject.assemble_with(params);
28
29
  end
29
30
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: the_grid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergiy Stotskiy
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-25 00:00:00.000000000 Z
12
+ date: 2013-05-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord