kaminari-api-meta-data 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +21 -0
- data/README.md +101 -0
- data/Rakefile +10 -0
- data/VERSION +1 -0
- data/lib/kaminari_api_meta_data.rb +16 -0
- data/lib/kaminari_api_meta_data/version.rb +3 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5d42adddaf528dbe79396b537d685d14c9445b31
|
4
|
+
data.tar.gz: 90a1a861da4fd94acd6f488d6e7681f3601d7c6b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 472ef4e95fef8ae7619300373502efedbf7c516df9fce02960331ff8f7e969d2115a3e405cc77e556b456ad043c909d03421cb6a8f6dbc58a1322a163d3abb09
|
7
|
+
data.tar.gz: 3c6d660c34da94cbf726129298eefcfb6323175ba8aad923812c36459450f116f2377755190017a83e93190bddcc0b6819b71f337354004b0330b0bb210d75cf
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Stuart Chinery
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
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,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
# Kaminari API Meta Data
|
2
|
+
|
3
|
+
A gem for adding [Kaminari](https://github.com/kaminari/kaminari) collection meta data to your API responses that matches the format that works with the Kaminari [`paginate`](https://github.com/kaminari/kaminari#the-paginate-helper-method) helper method.
|
4
|
+
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/kaminari-api-meta-data.svg)](https://badge.fury.io/rb/kaminari-api-meta-data)
|
6
|
+
[![Build Status](https://travis-ci.org/sleepingstu/kaminari-api-meta-data.svg?branch=master)](https://travis-ci.org/sleepingstu/kaminari-api-meta-data)
|
7
|
+
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem "kaminari-api-meta-data", require: "kaminari_api_meta_data"
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
```bash
|
20
|
+
$ bundle
|
21
|
+
```
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
```bash
|
26
|
+
$ gem install kaminari-api-meta-data
|
27
|
+
```
|
28
|
+
|
29
|
+
and then add `require "kaminari_api_meta_data"` to your Ruby file(s)
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
Add the include to your class, in this example using the `ApplicationController` from a Rails API project.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
class ApplicationController < ActionController::API
|
37
|
+
|
38
|
+
include ::KaminariApiMetaData
|
39
|
+
|
40
|
+
# ...
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
Then in a controller method use something like:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
def index
|
48
|
+
@things = Thing.unscoped.page(params[:page]).per(20)
|
49
|
+
|
50
|
+
render json: @things, root: :things, meta: meta_data(@things)
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
This will return JSON like so:
|
55
|
+
|
56
|
+
```json
|
57
|
+
{
|
58
|
+
"things": [],
|
59
|
+
"meta": {
|
60
|
+
"current_page": 1,
|
61
|
+
"next_page": 2,
|
62
|
+
"per_page": 20,
|
63
|
+
"prev_page": null,
|
64
|
+
"total_pages": 5,
|
65
|
+
"total_count": 91
|
66
|
+
}
|
67
|
+
}
|
68
|
+
```
|
69
|
+
|
70
|
+
### Additional Meta Data
|
71
|
+
|
72
|
+
It is possible to extend the meta data returned by providing an optional Hash of properties to the `meta_data` method.
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
meta = meta_data(@things, foo: "bar")
|
76
|
+
puts meta
|
77
|
+
# {
|
78
|
+
# current_page: 1,
|
79
|
+
# next_page: 2,
|
80
|
+
# per_page: 20,
|
81
|
+
# prev_page: nil,
|
82
|
+
# total_pages: 5,
|
83
|
+
# total_count: 91,
|
84
|
+
# foo: "bar"
|
85
|
+
# }
|
86
|
+
```
|
87
|
+
|
88
|
+
## Contributing
|
89
|
+
|
90
|
+
* Check out the latest master and/or develop branches to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
91
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
92
|
+
* Fork the project
|
93
|
+
* Start a feature/bugfix branch off of develop (using Git Flow approach)
|
94
|
+
* Commit and push until you are happy with your contribution
|
95
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally
|
96
|
+
* When you are done generate a pull request
|
97
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
98
|
+
|
99
|
+
## License
|
100
|
+
|
101
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "kaminari_api_meta_data/version"
|
2
|
+
|
3
|
+
module KaminariApiMetaData
|
4
|
+
|
5
|
+
def meta_data(collection, extra_meta = {})
|
6
|
+
{
|
7
|
+
current_page: collection.current_page,
|
8
|
+
next_page: collection.next_page,
|
9
|
+
per_page: collection.limit_value,
|
10
|
+
prev_page: collection.prev_page,
|
11
|
+
total_pages: collection.total_pages,
|
12
|
+
total_count: collection.total_count
|
13
|
+
}.merge(extra_meta)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kaminari-api-meta-data
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stuart Chinery
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: kaminari
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.13'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest-reporters
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mocha
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.2'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
description: A gem for adding Kaminari collection meta data to your API responses
|
98
|
+
that matches the format that works with Kaminari paginate method.
|
99
|
+
email:
|
100
|
+
- stuart.chinery@gmail.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- MIT-LICENSE
|
106
|
+
- README.md
|
107
|
+
- Rakefile
|
108
|
+
- VERSION
|
109
|
+
- lib/kaminari_api_meta_data.rb
|
110
|
+
- lib/kaminari_api_meta_data/version.rb
|
111
|
+
homepage: https://github.com/sleepingstu/kaminari-api-meta-data
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
metadata: {}
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 2.6.8
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: A gem for adding Kaminari collection meta data to your API responses
|
135
|
+
test_files: []
|