geared_pagination 1.0.1 → 1.1.1
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 +5 -3
- data/geared_pagination.gemspec +1 -1
- data/lib/geared_pagination/cursor.rb +2 -0
- data/lib/geared_pagination/page.rb +5 -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/cursor_test.rb +5 -0
- data/test/page_test.rb +7 -2
- data/test/portion_at_offset_test.rb +3 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 750005ac1e001628bcb41a5fc7ff8c3816882df33785ff6038833d17ea9ea895
|
4
|
+
data.tar.gz: 983b5d46b9cb9174b1ced7931a0015b2d202f7f3bd578d6fd0172878ba57947a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e66422eaa4008173bef8c798283f9b56a73853e88453b7d12fee2a6f5e0d0c88af0ab145fd83972bd41af017cafe35c4e306750aa75cb556ffd2bb51c465f208
|
7
|
+
data.tar.gz: 5e76d1a248cf859854b3c53eaaadcba3d14f11e4dd14dafbbca2cef30eeb1f6d791b35db386a9131eb2b9f0e4671921dcbd6171005da0f4d9dca90e0bbe9b453
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
geared_pagination (1.
|
4
|
+
geared_pagination (1.1.1)
|
5
5
|
activesupport (>= 5.0)
|
6
6
|
addressable (>= 2.5.0)
|
7
7
|
|
@@ -82,14 +82,16 @@ GEM
|
|
82
82
|
marcel (0.3.3)
|
83
83
|
mimemagic (~> 0.3.2)
|
84
84
|
method_source (1.0.0)
|
85
|
-
mimemagic (0.3.
|
85
|
+
mimemagic (0.3.10)
|
86
|
+
nokogiri (~> 1)
|
87
|
+
rake
|
86
88
|
mini_mime (1.0.2)
|
87
89
|
mini_portile2 (2.4.0)
|
88
90
|
minitest (5.14.0)
|
89
91
|
nio4r (2.5.2)
|
90
92
|
nokogiri (1.10.9)
|
91
93
|
mini_portile2 (~> 2.4.0)
|
92
|
-
public_suffix (4.0.
|
94
|
+
public_suffix (4.0.6)
|
93
95
|
rack (2.2.2)
|
94
96
|
rack-test (1.1.0)
|
95
97
|
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
|
|
data/test/cursor_test.rb
CHANGED
@@ -7,6 +7,11 @@ class GearedPagination::CursorTest < ActiveSupport::TestCase
|
|
7
7
|
assert_equal 1, GearedPagination::Cursor.from_param(" ").page_number
|
8
8
|
end
|
9
9
|
|
10
|
+
test "from an invalid param" do
|
11
|
+
assert_equal 1, GearedPagination::Cursor.from_param("aGVsbG8K").page_number
|
12
|
+
assert_equal 1, GearedPagination::Cursor.from_param("\o/ not base64").page_number
|
13
|
+
end
|
14
|
+
|
10
15
|
test "decode" do
|
11
16
|
assert_equal 1, GearedPagination::Cursor.decode("eyJwYWdlX251bWJlciI6MX0=").page_number
|
12
17
|
end
|
data/test/page_test.rb
CHANGED
@@ -20,8 +20,13 @@ class GearedPagination::PageTest < ActiveSupport::TestCase
|
|
20
20
|
end
|
21
21
|
|
22
22
|
test "last with page number greater than page count" do
|
23
|
-
|
24
|
-
|
23
|
+
assert_not GearedPagination::Recordset.new(Recording.none, per_page: 1000).page(2).last?
|
24
|
+
end
|
25
|
+
|
26
|
+
test "before_last" do
|
27
|
+
assert GearedPagination::Recordset.new(Recording.all, per_page: 1).page(1).before_last?
|
28
|
+
assert_not GearedPagination::Recordset.new(Recording.all, per_page: 1000).page(1).before_last?
|
29
|
+
assert_not GearedPagination::Recordset.new(Recording.none, per_page: 1000).page(2).before_last?
|
25
30
|
end
|
26
31
|
|
27
32
|
test "next offset param" do
|
@@ -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.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -177,7 +177,7 @@ 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.
|
180
|
+
rubygems_version: 3.1.4
|
181
181
|
signing_key:
|
182
182
|
specification_version: 4
|
183
183
|
summary: Paginate Active Record sets at variable speeds
|