geared_pagination 1.0.1 → 1.0.2

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
  SHA256:
3
- metadata.gz: c3e2956267a150a716db8afc9a1e0a9b03ac14906162faa283d5de88624b2f21
4
- data.tar.gz: 85222f625262561aafae1025403375f21adc4fb3b78d750d68929183dcd2269b
3
+ metadata.gz: 6c0df2ffda60431042065c8239bc92687ff300db3d4e6ffaa0f711334004ce7b
4
+ data.tar.gz: 5dbc61434adb9fe75618fb3e0ab075eea9abf90867de2e3f104cf1435b10a91e
5
5
  SHA512:
6
- metadata.gz: ebaba73472a04348a60e2e73b679dc4040f39e9b2193816bdda3c111c3a6dc9d16bcf944d4a4adf3c41b9636f6f4d194d21137dcf652f727e3223ae0576b21b1
7
- data.tar.gz: 657c6f6d8d0ee877910fb0f394e5229928325af59c471aa48c8bcddb34c75a824a5c92a128bb60757d2178205c914e3aaf3c2c96adcff036fba0098a30c7e3fe
6
+ metadata.gz: 1a789e055a1a1a6686e64dbd2bffc91e39caca801dfaee071fe6a1afd9a445fc006b01b4df2917dd1befaafb26278331ddadce9d7f2c2714b42c4f98e394632b
7
+ data.tar.gz: 0d635bfa95bbedcb9e34111413d60d1fb486dcbc80d2a2567921525fc2170b8e637a4bd65ef9cc2235ed2446c9c3ecfa3060e6ce45cae662eed5c0ec6b785f16
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ *.gem
1
2
  .byebug_history
2
3
 
3
4
  test/dummy/db/*.sqlite3
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- geared_pagination (1.0.1)
4
+ geared_pagination (1.0.2)
5
5
  activesupport (>= 5.0)
6
6
  addressable (>= 2.5.0)
7
7
 
@@ -89,7 +89,7 @@ GEM
89
89
  nio4r (2.5.2)
90
90
  nokogiri (1.10.9)
91
91
  mini_portile2 (~> 2.4.0)
92
- public_suffix (4.0.5)
92
+ public_suffix (4.0.6)
93
93
  rack (2.2.2)
94
94
  rack-test (1.1.0)
95
95
  rack (>= 1.0, < 3)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'geared_pagination'
3
- s.version = '1.0.1'
3
+ s.version = '1.0.2'
4
4
  s.authors = 'David Heinemeier Hansson'
5
5
  s.email = 'david@basecamp.com'
6
6
  s.summary = 'Paginate Active Record sets at variable speeds'
@@ -34,7 +34,7 @@ module GearedPagination
34
34
  end
35
35
 
36
36
  def orderings
37
- orders.to_h { |order| [ order.attribute, order.direction ] }
37
+ orders.map { |order| [ order.attribute, order.direction ] }.to_h
38
38
  end
39
39
 
40
40
  def limit
@@ -17,7 +17,10 @@ module GearedPagination
17
17
  end
18
18
 
19
19
  def offset
20
- (page_number - 1).times.sum { |index| ratios[index + 1] }
20
+ variable = [(page_number - 1), ratios.size - 1].min.times.sum { |index| ratios[index + 1] }
21
+ fixed = [page_number - ratios.size, 0].max * ratios.fixed
22
+
23
+ variable + fixed
21
24
  end
22
25
 
23
26
  def next_param(*)
@@ -3,15 +3,23 @@ module GearedPagination
3
3
  DEFAULTS = [ 15, 30, 50, 100 ]
4
4
 
5
5
  def initialize(ratios = nil)
6
- @ratios = Array(ratios || DEFAULTS)
6
+ @ratios = Array(ratios || DEFAULTS).map(&:to_i)
7
7
  end
8
8
 
9
9
  def [](page_number)
10
- @ratios[page_number - 1] || @ratios.last
10
+ @ratios[page_number - 1] || fixed
11
11
  end
12
12
 
13
13
  def cache_key
14
14
  @ratios.join('-')
15
15
  end
16
+
17
+ def size
18
+ @ratios.size
19
+ end
20
+
21
+ def fixed
22
+ @ratios.last
23
+ end
16
24
  end
17
25
  end
@@ -14,6 +14,9 @@ class GearedPagination::ControllerTest < ActionController::TestCase
14
14
  assert_equal etag_for("placeholder", "page/1:1-2"), response.etag
15
15
  etag_before_gearing_change = response.etag
16
16
 
17
+ get :index, params: { page: 2, per_page: [ 1, 2 ] }
18
+ assert_equal etag_for("placeholder", "page/2:1-2"), response.etag
19
+
17
20
  get :index, params: { page: 1, per_page: [ 1, 2 ] }
18
21
  assert_equal etag_before_gearing_change, response.etag
19
22
 
@@ -7,6 +7,9 @@ class GearedPagination::PortionAtOffsetTest < ActiveSupport::TestCase
7
7
  assert_equal 0, GearedPagination::PortionAtOffset.new(page_number: 1).offset
8
8
  assert_equal GearedPagination::Ratios::DEFAULTS.first, GearedPagination::PortionAtOffset.new(page_number: 2).offset
9
9
  assert_equal GearedPagination::Ratios::DEFAULTS.first + GearedPagination::Ratios::DEFAULTS.second, GearedPagination::PortionAtOffset.new(page_number: 3).offset
10
+ assert_equal 4.times.sum { |index| GearedPagination::Ratios::DEFAULTS[index] || GearedPagination::Ratios::DEFAULTS.last }, GearedPagination::PortionAtOffset.new(page_number: 5).offset
11
+ assert_equal 5.times.sum { |index| GearedPagination::Ratios::DEFAULTS[index] || GearedPagination::Ratios::DEFAULTS.last }, GearedPagination::PortionAtOffset.new(page_number: 6).offset
12
+ assert_equal 9.times.sum { |index| GearedPagination::Ratios::DEFAULTS[index] || GearedPagination::Ratios::DEFAULTS.last }, GearedPagination::PortionAtOffset.new(page_number: 10).offset
10
13
  end
11
14
 
12
15
  test "limit" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geared_pagination
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-28 00:00:00.000000000 Z
11
+ date: 2020-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.12'
55
- description:
55
+ description:
56
56
  email: david@basecamp.com
57
57
  executables: []
58
58
  extensions: []
@@ -162,7 +162,7 @@ homepage: https://github.com/basecamp/geared_pagination
162
162
  licenses:
163
163
  - MIT
164
164
  metadata: {}
165
- post_install_message:
165
+ post_install_message:
166
166
  rdoc_options: []
167
167
  require_paths:
168
168
  - lib
@@ -177,8 +177,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
177
  - !ruby/object:Gem::Version
178
178
  version: '0'
179
179
  requirements: []
180
- rubygems_version: 3.1.2
181
- signing_key:
180
+ rubygems_version: 3.0.3
181
+ signing_key:
182
182
  specification_version: 4
183
183
  summary: Paginate Active Record sets at variable speeds
184
184
  test_files: