grape-kaminari 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: f7a8c5230ae29829672e54245091c948c65b12be
4
- data.tar.gz: 3d43e68afdbebfc4987eebb206296c376d8a3abb
3
+ metadata.gz: 821c1238aa91cec3b1fc14a13a38fa2a56400947
4
+ data.tar.gz: 4b6d71cd54352512607b1ca306975601421ca833
5
5
  SHA512:
6
- metadata.gz: 1bded3a46f9aa34a8006b1941a4a5d6ab4b47a9c2ef6c88889cc28adfdcde5bae158b43d517042da1031929d3882933d3b7a54a4ee41c7ce22d2eabaa1b977bc
7
- data.tar.gz: 2024105c17eed72397afad38716b771425ae7de82bb1f2f341870bc3617d4facc95afbf640e1d00403371c8c377b5660f7fe8815d2d8e5eb1ec6b6175872c167
6
+ metadata.gz: 3ceb594a017b53ef808c3b61b1ae13e2d3644ef0d03bebf3b7608a4167512efd4706e15a04e2159ee18424bf99c9dbbd763485ccfac7d0e7cbec148b43d0f063
7
+ data.tar.gz: 53ee0596172838efd88fcf8d2f7f728a2f92786b76c318eb0df11a828f0a76e358ed67b0890044e72a8d28899389797bcc48ecc7c3aefa7f4b346b13f59408f1
data/LICENSE.txt CHANGED
@@ -1,22 +1,20 @@
1
- Copyright (c) 2013 Monterail.com
1
+ The MIT License (MIT)
2
2
 
3
- MIT License
3
+ Copyright (c) 2013-2014 Monterail.com LLC
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
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
- included in all copies or substantial portions of the Software.
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
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
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 [![Gem Version](https://badge.fury.io/rb/grape-kaminari.png)](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
- paginate :per_page => 20
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 wil be paginated and also will include pagination headers
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
@@ -1,5 +1,5 @@
1
1
  module Grape
2
2
  module Kaminari
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -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!(per_page: 10)
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.0
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: 2013-12-06 00:00:00.000000000 Z
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: