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 +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +2 -2
- data/geared_pagination.gemspec +1 -1
- data/lib/geared_pagination/portions/portion_at_cursor.rb +1 -1
- data/lib/geared_pagination/portions/portion_at_offset.rb +4 -1
- data/lib/geared_pagination/ratios.rb +10 -2
- data/test/controller_test.rb +3 -0
- data/test/portion_at_offset_test.rb +3 -0
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c0df2ffda60431042065c8239bc92687ff300db3d4e6ffaa0f711334004ce7b
|
4
|
+
data.tar.gz: 5dbc61434adb9fe75618fb3e0ab075eea9abf90867de2e3f104cf1435b10a91e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a789e055a1a1a6686e64dbd2bffc91e39caca801dfaee071fe6a1afd9a445fc006b01b4df2917dd1befaafb26278331ddadce9d7f2c2714b42c4f98e394632b
|
7
|
+
data.tar.gz: 0d635bfa95bbedcb9e34111413d60d1fb486dcbc80d2a2567921525fc2170b8e637a4bd65ef9cc2235ed2446c9c3ecfa3060e6ce45cae662eed5c0ec6b785f16
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
geared_pagination (1.0.
|
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.
|
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)
|
data/geared_pagination.gemspec
CHANGED
@@ -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] ||
|
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
|
data/test/controller_test.rb
CHANGED
@@ -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.
|
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-
|
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.
|
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:
|