grape-pagy 0.2.0 → 0.3.0

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: ae85f7bb6472d19bcbedad2d0e03e0960a75615960819251b1a35ed793a0cb65
4
- data.tar.gz: 3fa36e9bcd909ae16e54c44c0c9b65499fa8f4ad7dbf94c75b8d7192897932b5
3
+ metadata.gz: 5956682171c97b589bba13991d1f810f73bcdbc95ef24ca169d16a4f19085713
4
+ data.tar.gz: 590ec8ca32ad36c166875b095e874036b46f45f0c32a53999ee8f7f083cfb0b7
5
5
  SHA512:
6
- metadata.gz: 74772e142b4277e609bdca9ce59e5a3de4ed35e940fbbf3a8a0dd79122bdacf9327acf832177b9ce92cb074a81be34c1fae30ea9a2871e36800ba6d19fd68905
7
- data.tar.gz: 65407c449ede7a7cfa7a3e1d7428530bc761b5c776a30a0db90baeacd234596e7b5fc933e34d50aa8cbf2011359a65a68bd9e9f29819c637edb1986f2a66a36e
6
+ metadata.gz: 77257d503b9a5ab54e33d722f971ff2b095e0317010820f6388f1a1a19eaff47fc5fb1baae3a83b856eb26e2561f140df3d084b1055dfd297ffd5aadbb92a30a
7
+ data.tar.gz: a8491d340672664083ebebfb4b66df017a8272eade89966a8a38bf92be001ee526ce8d1b9efe105a09caf0e580a533687b2dd913d0a2077bc3071e3e45a1c302
@@ -1,3 +1,7 @@
1
+ ### 0.3.0
2
+
3
+ * Allow countless usage [#2](https://github.com/bsm/grape-pagy/pull/2).
4
+
1
5
  ### 0.2.0
2
6
 
3
7
  * Improved, simplified and stabilised API [#1](https://github.com/bsm/grape-pagy/pull/1).
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grape-pagy (0.2.0)
4
+ grape-pagy (0.3.0)
5
5
  grape (>= 1.5)
6
6
  pagy
7
7
 
@@ -94,10 +94,10 @@ GEM
94
94
  ruby-progressbar (1.10.1)
95
95
  ruby2_keywords (0.0.2)
96
96
  thread_safe (0.3.6)
97
- tzinfo (1.2.7)
97
+ tzinfo (1.2.8)
98
98
  thread_safe (~> 0.1)
99
99
  unicode-display_width (1.7.0)
100
- zeitwerk (2.4.0)
100
+ zeitwerk (2.4.1)
101
101
 
102
102
  PLATFORMS
103
103
  ruby
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'grape-pagy'
3
- spec.version = '0.2.0'
3
+ spec.version = '0.3.0'
4
4
  spec.authors = ['Black Square Media']
5
5
  spec.email = ['info@blacksquaremedia.com']
6
6
  spec.description = 'Pagy paginator for grape API'
@@ -2,6 +2,7 @@ require 'grape'
2
2
  require 'pagy'
3
3
  require 'pagy/extras/arel'
4
4
  require 'pagy/extras/array'
5
+ require 'pagy/extras/countless'
5
6
  require 'pagy/extras/headers'
6
7
  require 'pagy/extras/items'
7
8
  require 'pagy/extras/overflow'
@@ -11,15 +12,15 @@ module Grape
11
12
  Wrapper = Struct.new :request, :params do
12
13
  include ::Pagy::Backend
13
14
 
14
- def paginate(collection, via: nil, **opts, &block)
15
+ def paginate(collection, using: nil, **opts, &block)
15
16
  pagy_with_items(opts)
16
- via ||= if collection.respond_to?(:arel_table)
17
- :arel
18
- elsif collection.is_a?(Array)
19
- :array
20
- end
17
+ using ||= if collection.respond_to?(:arel_table)
18
+ :arel
19
+ elsif collection.is_a?(Array)
20
+ :array
21
+ end
21
22
 
22
- method = [:pagy, via].compact.join('_')
23
+ method = [:pagy, using].compact.join('_')
23
24
  page, scope = send(method, collection, **opts)
24
25
 
25
26
  pagy_headers(page).each(&block)
@@ -50,6 +50,25 @@ describe Grape::Pagy do
50
50
  expect(last_response.body).to eq(%([]))
51
51
  end
52
52
 
53
+ it 'should allow countless mode' do
54
+ get '/countless?page=2'
55
+ expect(last_response.status).to eq(200)
56
+ expect(last_response.headers).to include(
57
+ 'Current-Page' => '2',
58
+ 'Page-Items' => '3',
59
+ 'Link' => [
60
+ %(<http://example.org/countless?page=1>; rel="first"),
61
+ %(<http://example.org/countless?page=1>; rel="prev"),
62
+ %(<http://example.org/countless?page=3>; rel="next"),
63
+ ].join(', '),
64
+ )
65
+ expect(last_response.headers).not_to include(
66
+ 'Total-Count',
67
+ 'Total-Pages',
68
+ )
69
+ expect(last_response.body).to eq(%([4, 5, 6]))
70
+ end
71
+
53
72
  it 'should inherit helper' do
54
73
  get '/sub'
55
74
  expect(last_response.status).to eq(200)
@@ -7,6 +7,16 @@ require 'rack/test'
7
7
  Pagy::VARS[:items] = 10
8
8
  Pagy::VARS[:max_items] = 20
9
9
 
10
+ class TestArray < Array
11
+ def limit(num)
12
+ slice!(0, num)
13
+ end
14
+
15
+ def offset(num)
16
+ slice!(num..-1)
17
+ end
18
+ end
19
+
10
20
  class TestAPI < Grape::API
11
21
  helpers Grape::Pagy::Helpers
12
22
 
@@ -17,6 +27,13 @@ class TestAPI < Grape::API
17
27
  pagy (1..12).to_a
18
28
  end
19
29
 
30
+ params do
31
+ use :pagy, items: 3
32
+ end
33
+ get '/countless' do
34
+ pagy TestArray.new((1..12).to_a), using: :countless
35
+ end
36
+
20
37
  resource :sub do
21
38
  params do
22
39
  use :pagy, items_param: :per_page
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-pagy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Black Square Media
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-08 00:00:00.000000000 Z
11
+ date: 2020-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape