captive-api 1.2.0 → 1.2.2
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 +4 -4
- data/README.md +25 -0
- data/app/controllers/concerns/api/pagination_concern.rb +10 -7
- data/lib/captive/api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a01f0b4ab99a8be426c2493906cf594c2bb83b2352fa8f349a40ecd874e124e
|
4
|
+
data.tar.gz: c76b53de10722bbc7742407e2e0a92941575ecab744cb0151f5fdb9e1f957b8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e1d3821a3ce9666244d936ceb5efac1a6cd4b3fb6f9cb9088b47143fd6a2a410be4565014c16cf487af025eb5dd8bf171ba1fa1ad3ec75541c6eea666fc9ff5
|
7
|
+
data.tar.gz: 6cfabdb966ab7241844caf91e2dfa78db26bf5cb7afcb126822ac8ae661c6b3bb9f6cdf89ff933f0a5460758d9f2c00287782d03c7b068e248591a9fd7568d75
|
data/README.md
CHANGED
@@ -27,6 +27,31 @@ The class `Captive::Api::ApplicationController` includes 2 concerns :
|
|
27
27
|
| [pagination](https://github.com/Captive-Studio/captive-api/blob/main/app/controllers/concerns/api/pagination_concern.rb) | Logique de pagination pour les index |
|
28
28
|
| [render error](https://github.com/Captive-Studio/captive-api/blob/main/app/controllers/concerns/api/render_error_concern.rb) | Attrape certaines erreurs pour retourner une page d'erreur en json. Permet aussi d'utiliser les méthodes pour rendre des pages d'erreur json manuellement |
|
29
29
|
|
30
|
+
### PaginationConcern
|
31
|
+
|
32
|
+
#### `#pagination`
|
33
|
+
|
34
|
+
You can use the pagination method like this :
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
@tenues = @tenues.page(pagination[:page])
|
38
|
+
.per(pagination[:per_page])
|
39
|
+
```
|
40
|
+
|
41
|
+
*The method `page` and `per` come from [will_paginate](https://github.com/mislav/will_paginate)*
|
42
|
+
|
43
|
+
The pagination method return an hash like this :
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
{ page: 1, per_page: 10 }
|
47
|
+
```
|
48
|
+
|
49
|
+
⚠️ The first page is `1` and not `0` !
|
50
|
+
|
51
|
+
### RenderErrorConcern
|
52
|
+
|
53
|
+
TODO
|
54
|
+
|
30
55
|
## Installation
|
31
56
|
Add this line to your application's Gemfile:
|
32
57
|
|
@@ -10,15 +10,18 @@ module Api
|
|
10
10
|
module PaginationConcern
|
11
11
|
extend ActiveSupport::Concern
|
12
12
|
|
13
|
-
included do
|
14
|
-
MAX_ITEMS_PAR_PAGE
|
15
|
-
DEFAULT_NB_ITEMS_PAR_PAGE
|
13
|
+
included do |base|
|
14
|
+
base.const_set :MAX_ITEMS_PAR_PAGE, 100
|
15
|
+
base.const_set :DEFAULT_NB_ITEMS_PAR_PAGE, 10
|
16
16
|
|
17
17
|
def pagination
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
@pagination ||=
|
19
|
+
begin
|
20
|
+
par_page = (params[:per_page] || self.class::DEFAULT_NB_ITEMS_PAR_PAGE).to_i
|
21
|
+
par_page = self.class::MAX_ITEMS_PAR_PAGE if par_page > self.class::MAX_ITEMS_PAR_PAGE
|
22
|
+
page = (params[:page] || 1).to_i
|
23
|
+
{ page: page, per_page: par_page }
|
24
|
+
end
|
22
25
|
end
|
23
26
|
end
|
24
27
|
end
|
data/lib/captive/api/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: captive-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Captive
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-07-
|
12
|
+
date: 2023-07-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|