pager_api 0.2.3 → 0.2.4
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 +5 -5
- data/.github/PULL_REQUEST_TEMPLATE.md +3 -0
- data/README.md +19 -17
- data/lib/generators/pager_api/templates/pager_api.rb +3 -0
- data/lib/pager_api/pagination/kaminari.rb +2 -1
- data/lib/pager_api/pagination/will_paginate.rb +2 -1
- data/lib/pager_api/railtie.rb +1 -2
- data/lib/pager_api/version.rb +1 -1
- data/lib/pager_api.rb +4 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 26830a930c08e28898bc2b08427937a650edbacdfa3f30ba5e772a00f106f853
|
4
|
+
data.tar.gz: 0d0ce3d051f008887e2a12056583446d3fd3eee62590928bca58635d874410ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c14e9e1d77e18b61ba966320e413746107f8e2535cbd5c57b9cca149b6578d6f65050c4a08c607bd2e91b277321adaa5a807016d63cb5329ba4e2147bda43918
|
7
|
+
data.tar.gz: 7353b9e6620269f4b87f9e01a89c3457542e89a0caf37327227e2fb4235dd9f60babc031841e638b583c2dd6c0e69068b1484e6b6a5af211e86cebaf0415188b
|
data/README.md
CHANGED
@@ -80,15 +80,18 @@ In the controller where you are providing a paginated collection, you may have s
|
|
80
80
|
|
81
81
|
```ruby
|
82
82
|
class UsersController < ApplicationController
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
83
|
+
def index
|
84
|
+
users = User.page(params[:page]).per(15)
|
85
|
+
|
86
|
+
render json: users,
|
87
|
+
meta: {
|
88
|
+
pagination: {
|
89
|
+
per_page: 15,
|
90
|
+
total_pages: 10,
|
91
|
+
total_objects: 150
|
92
|
+
}
|
93
|
+
}
|
94
|
+
end
|
92
95
|
end
|
93
96
|
```
|
94
97
|
|
@@ -96,12 +99,11 @@ With `pager_api` it is really easy to achieve the above by:
|
|
96
99
|
|
97
100
|
```ruby
|
98
101
|
class UsersController < ApplicationController
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
end
|
102
|
+
def index
|
103
|
+
# You can have any scope for the User class in this case
|
104
|
+
# You can even send the paginated collection
|
105
|
+
paginate User.unscoped, per_page: 15
|
106
|
+
end
|
105
107
|
end
|
106
108
|
```
|
107
109
|
|
@@ -132,8 +134,8 @@ By default it will also include a `Link` header with the following information:
|
|
132
134
|
|
133
135
|
```
|
134
136
|
# Link: <http://example.com/api/v1/users?page="2">; rel="next",
|
135
|
-
# <http://example.com/api/v1
|
136
|
-
# <http://example.com/api/v1
|
137
|
+
# <http://example.com/api/v1/users?page="5">; rel="last",
|
138
|
+
# <http://example.com/api/v1/users?page="1">; rel="first",
|
137
139
|
# <http://example.com/api/v1/users?page="1">; rel="prev",
|
138
140
|
```
|
139
141
|
|
@@ -16,6 +16,9 @@ PagerApi.setup do |config|
|
|
16
16
|
#
|
17
17
|
# config.include_pagination_headers = true
|
18
18
|
|
19
|
+
# Set the Total-Pages Header name
|
20
|
+
# config.total_pages_header = "X-Total-Pages"
|
21
|
+
|
19
22
|
# Set the Total-Count Header name
|
20
23
|
# config.total_count_header = "X-Total-Count"
|
21
24
|
end
|
@@ -34,7 +34,8 @@ module PagerApi
|
|
34
34
|
end
|
35
35
|
|
36
36
|
headers['Link'] = links.join(", ") unless links.empty?
|
37
|
-
headers[PagerApi.
|
37
|
+
headers[PagerApi.total_pages_header] = collection.total_pages
|
38
|
+
headers[PagerApi.total_count_header] = collection.total_count
|
38
39
|
|
39
40
|
return nil
|
40
41
|
end
|
@@ -35,7 +35,8 @@ module PagerApi
|
|
35
35
|
end
|
36
36
|
|
37
37
|
headers['Link'] = links.join(", ") unless links.empty?
|
38
|
-
headers[PagerApi.
|
38
|
+
headers[PagerApi.total_pages_header] = collection.total_pages
|
39
|
+
headers[PagerApi.total_count_header] = collection.total_entries
|
39
40
|
|
40
41
|
return nil
|
41
42
|
end
|
data/lib/pager_api/railtie.rb
CHANGED
data/lib/pager_api/version.rb
CHANGED
data/lib/pager_api.rb
CHANGED
@@ -12,6 +12,10 @@ module PagerApi
|
|
12
12
|
mattr_accessor :include_pagination_headers
|
13
13
|
@@include_pagination_headers = true
|
14
14
|
|
15
|
+
# Total Pages Header name
|
16
|
+
mattr_accessor :total_pages_header
|
17
|
+
@@total_pages_header = "X-Total-Pages"
|
18
|
+
|
15
19
|
# Total Count Header name
|
16
20
|
mattr_accessor :total_count_header
|
17
21
|
@@total_count_header = "X-Total-Count"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pager_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abraham Kuri
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -47,6 +47,7 @@ extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
49
|
- ".codeclimate.yml"
|
50
|
+
- ".github/PULL_REQUEST_TEMPLATE.md"
|
50
51
|
- ".gitignore"
|
51
52
|
- ".rspec"
|
52
53
|
- ".rubocop.yml"
|
@@ -86,8 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
87
|
- !ruby/object:Gem::Version
|
87
88
|
version: '0'
|
88
89
|
requirements: []
|
89
|
-
|
90
|
-
rubygems_version: 2.5.1
|
90
|
+
rubygems_version: 3.0.3
|
91
91
|
signing_key:
|
92
92
|
specification_version: 4
|
93
93
|
summary: A Rails pagination JSON handler, perfect for API
|