grape-kaminari 0.1.0 → 0.1.1
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/LICENSE.txt +16 -18
- data/README.md +5 -3
- data/lib/grape/kaminari/max_value_validator.rb +14 -0
- data/lib/grape/kaminari/version.rb +1 -1
- data/lib/grape/kaminari.rb +7 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 821c1238aa91cec3b1fc14a13a38fa2a56400947
|
4
|
+
data.tar.gz: 4b6d71cd54352512607b1ca306975601421ca833
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ceb594a017b53ef808c3b61b1ae13e2d3644ef0d03bebf3b7608a4167512efd4706e15a04e2159ee18424bf99c9dbbd763485ccfac7d0e7cbec148b43d0f063
|
7
|
+
data.tar.gz: 53ee0596172838efd88fcf8d2f7f728a2f92786b76c318eb0df11a828f0a76e358ed67b0890044e72a8d28899389797bcc48ecc7c3aefa7f4b346b13f59408f1
|
data/LICENSE.txt
CHANGED
@@ -1,22 +1,20 @@
|
|
1
|
-
|
1
|
+
The MIT License (MIT)
|
2
2
|
|
3
|
-
|
3
|
+
Copyright (c) 2013-2014 Monterail.com LLC
|
4
4
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
the following conditions:
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
12
11
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
15
14
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Grape::Kaminari
|
1
|
+
# Grape::Kaminari [](http://badge.fury.io/rb/grape-kaminari)
|
2
2
|
|
3
3
|
[kaminari](https://github.com/amatsuda/kaminari) paginator integration for [grape](https://github.com/intridea/grape) API framework.
|
4
4
|
|
@@ -35,7 +35,9 @@ class MyApi < Grape::API
|
|
35
35
|
# Annotate action with `paginate`.
|
36
36
|
# This will add two optional params: page and per_page
|
37
37
|
# You can optionally overwrite the default :per_page setting (10)
|
38
|
-
|
38
|
+
# and the :max_per_page(false/disabled) setting which will use a validator to
|
39
|
+
# check that per_page is below the given number.
|
40
|
+
paginate :per_page => 20, :max_per_page => 30
|
39
41
|
|
40
42
|
get do
|
41
43
|
posts = Post.where(...)
|
@@ -54,7 +56,7 @@ Now you can make a HTTP request to you are endpoint with `page` (and `per_page`)
|
|
54
56
|
curl -v http://host.dev/api/posts?page=3
|
55
57
|
```
|
56
58
|
|
57
|
-
and the response
|
59
|
+
and the response will be paginated and also will include pagination headers
|
58
60
|
|
59
61
|
```
|
60
62
|
X-Total: 42
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Grape
|
2
|
+
module Kaminari
|
3
|
+
class MaxValueValidator < Grape::Validations::SingleOptionValidator
|
4
|
+
def validate_param!(attr_name, params)
|
5
|
+
return unless params[attr_name]
|
6
|
+
|
7
|
+
attr = params[attr_name]
|
8
|
+
if attr && @option && attr > @option
|
9
|
+
raise Grape::Exceptions::Validation, param: @scope.full_name(attr_name), message: "must be less than #{@option}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/grape/kaminari.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "grape/kaminari/version"
|
2
|
+
require "grape/kaminari/max_value_validator"
|
2
3
|
require "kaminari/grape"
|
3
4
|
|
4
5
|
module Grape
|
@@ -17,12 +18,16 @@ module Grape
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def self.paginate(options = {})
|
20
|
-
options.reverse_merge!(
|
21
|
+
options.reverse_merge!(
|
22
|
+
per_page: 10,
|
23
|
+
max_per_page: false
|
24
|
+
)
|
21
25
|
params do
|
22
26
|
optional :page, type: Integer, default: 1,
|
23
27
|
desc: 'Page offset to fetch.'
|
24
28
|
optional :per_page, type: Integer, default: options[:per_page],
|
25
|
-
desc: 'Number of results to return per page.'
|
29
|
+
desc: 'Number of results to return per page.',
|
30
|
+
max_value: options[:max_per_page]
|
26
31
|
end
|
27
32
|
end
|
28
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-kaminari
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tymon Tobolski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- grape-kaminari.gemspec
|
82
82
|
- lib/grape-kaminari.rb
|
83
83
|
- lib/grape/kaminari.rb
|
84
|
+
- lib/grape/kaminari/max_value_validator.rb
|
84
85
|
- lib/grape/kaminari/version.rb
|
85
86
|
homepage: ''
|
86
87
|
licenses:
|