wor-paginate 0.1.4 → 0.1.5a
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +12 -9
- data/CHANGELOG.md +8 -0
- data/Gemfile +1 -6
- data/README.md +66 -14
- data/lib/wor/paginate/formatter.rb +3 -2
- data/lib/wor/paginate/paginate.rb +10 -0
- data/lib/wor/paginate/version.rb +1 -1
- data/pull_request_template.md +3 -0
- data/wor-paginate.gemspec +2 -2
- metadata +12 -11
- data/Dangerfile +0 -69
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7bfb0360345a51c5eb2ab8ed52d90f3dc7032155830e37b48a83e09e049f1fd
|
4
|
+
data.tar.gz: f145fa8f27deb86310b600ff75b2623a620ea7445cfca7f387fabe2dcb000471
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cfa29bf30aacda22b8f2702018b078de0e1c1631aa5f51366bc69a9d5a2fe7fd74ec2514d44597357fc604912718205b756fe43e5cee68cb01f492659235fa9
|
7
|
+
data.tar.gz: 84576e26892ca4d718084e0d064323a0d46e73e209085409e8f77577f115aac38eb4fb491a05f50a7a95a531e55c0284a218946f0ae303e0151fd126c13e5ce8
|
data/.travis.yml
CHANGED
@@ -1,20 +1,23 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.
|
4
|
-
- 2.
|
5
|
-
- 2.
|
3
|
+
- 2.3.8
|
4
|
+
- 2.4.7
|
5
|
+
- 2.5.6
|
6
|
+
- 2.6.4
|
6
7
|
- ruby-head
|
7
8
|
|
9
|
+
before_install:
|
10
|
+
- gem install bundler -v 2.0.1
|
11
|
+
|
8
12
|
install:
|
9
|
-
-
|
10
|
-
- gem install danger --version '~> 5.0'
|
11
|
-
- bundle install --retry=3
|
13
|
+
- bundle _2.0.1_ install --retry=3
|
12
14
|
- bundle exec rake db:migrate RAILS_ENV=test -f spec/dummy/Rakefile
|
13
15
|
|
14
|
-
before_script:
|
15
|
-
- danger
|
16
|
-
|
17
16
|
script:
|
18
17
|
- bundle exec rubocop lib spec --format simple
|
19
18
|
- bundle exec rspec
|
20
19
|
- bundle exec codeclimate-test-reporter
|
20
|
+
|
21
|
+
matrix:
|
22
|
+
allow_failures:
|
23
|
+
- rvm : ruby-head
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## Change log
|
2
2
|
|
3
|
+
### V0.1.5a
|
4
|
+
* [#62](https://github.com/Wolox/wor-paginate/pull/62): Add options in active model serializer - [@blacksam07](https://github.com/blacksam07).
|
5
|
+
|
6
|
+
### V0.1.5
|
7
|
+
* [#59](https://github.com/Wolox/wor-paginate/pull/59): Add include option to serialize nested models - [@jcgrethe](https://github.com/jcgrethe).
|
8
|
+
* [#65](https://github.com/Wolox/wor-paginate/pull/65): Add scope on serializer - [@mtejedorwolox](https://github.com/mtejedorwolox).
|
9
|
+
* [#72](https://github.com/Wolox/wor-paginate/pull/72): Update readme and CI fix - [@mnmallea](https://github.com/mnmallea).
|
10
|
+
|
3
11
|
### V0.1.4
|
4
12
|
* [#57](https://github.com/Wolox/wor-paginate/pull/57): Update rails max version - [@hdf1986](https://github.com/hdf1986).
|
5
13
|
|
data/Gemfile
CHANGED
@@ -15,7 +15,7 @@ gemspec
|
|
15
15
|
|
16
16
|
group :development, :test do
|
17
17
|
gem 'active_model_serializers', '~> 0.10.0'
|
18
|
-
gem 'bundler', '~> 1
|
18
|
+
gem 'bundler', '~> 2.0.1'
|
19
19
|
gem 'byebug', '~> 9.0'
|
20
20
|
gem 'codeclimate-test-reporter', '~> 1.0.0'
|
21
21
|
gem 'database_cleaner', '~> 1.6.0'
|
@@ -33,8 +33,3 @@ group :development, :test do
|
|
33
33
|
gem 'webmock', '~> 3.0.0'
|
34
34
|
gem 'will_paginate', '~> 3.1.0'
|
35
35
|
end
|
36
|
-
|
37
|
-
group :test do
|
38
|
-
gem 'danger'
|
39
|
-
gem 'danger-todoist'
|
40
|
-
end
|
data/README.md
CHANGED
@@ -1,9 +1,28 @@
|
|
1
|
-
|
1
|
+
Wor::Paginate
|
2
|
+
=============
|
3
|
+
|
2
4
|
[![Build Status](https://travis-ci.org/Wolox/wor-paginate.svg?branch=master)](https://travis-ci.org/Wolox/wor-paginate)
|
3
5
|
[![Gem Version](https://badge.fury.io/rb/wor-paginate.svg)](https://badge.fury.io/rb/wor-paginate)
|
4
|
-
[![Dependency Status](https://gemnasium.com/badges/github.com/Wolox/wor-paginate.svg)](https://gemnasium.com/github.com/Wolox/wor-paginate)
|
5
6
|
[![Code Climate](https://codeclimate.com/github/Wolox/wor-paginate/badges/gpa.svg)](https://codeclimate.com/github/Wolox/wor-paginate)
|
6
|
-
|
7
|
+
|
8
|
+
# Table of contents
|
9
|
+
- [Description](#description)
|
10
|
+
- [Installation](#installation)
|
11
|
+
- [Usage](#usage)
|
12
|
+
- [Basic usage](#basic-usage)
|
13
|
+
- [Customizing output](#customizing-output)
|
14
|
+
- [Custom serializers](#custom-serializers)
|
15
|
+
- [Custom formatters](#custom-formatters)
|
16
|
+
- [Working with Kaminari or will_paginate](#working-with-kaminari-or-will_paginate)
|
17
|
+
- [Test helpers](#test-helpers)
|
18
|
+
- [Contributing](#contributing)
|
19
|
+
- [Releases](#releases)
|
20
|
+
- [About](#about)
|
21
|
+
- [License](#license)
|
22
|
+
|
23
|
+
-----------------------
|
24
|
+
|
25
|
+
## Description
|
7
26
|
|
8
27
|
Wor::Paginate is a gem for Rails that simplifies pagination, particularly for controller methods, while standardizing JSON output for APIs. It's meant to work both as a standalone pagination gem and as an extra layer over [Kaminari](https://github.com/kaminari/kaminari) and [will_paginate](https://github.com/mislav/will_paginate).
|
9
28
|
|
@@ -34,7 +53,7 @@ The basic use case is to paginate using default values. This is achieved by incl
|
|
34
53
|
include Wor::Paginate
|
35
54
|
|
36
55
|
def index
|
37
|
-
|
56
|
+
render_paginated DummyModel
|
38
57
|
end
|
39
58
|
end
|
40
59
|
```
|
@@ -57,7 +76,7 @@ The response to the index will then be:
|
|
57
76
|
"name": "i",
|
58
77
|
"something": 68
|
59
78
|
},
|
60
|
-
...
|
79
|
+
// ...
|
61
80
|
{
|
62
81
|
"id": 25,
|
63
82
|
"name": "2m",
|
@@ -85,6 +104,20 @@ render_paginated DummyModel, each_serializer: CustomDummyModelSerializer
|
|
85
104
|
```
|
86
105
|
where the serializer is just an [`ActiveModel::Serializer`](https://github.com/rails-api/active_model_serializers).
|
87
106
|
|
107
|
+
#### Custom options
|
108
|
+
Using custom options in serializer, example method `current_user`
|
109
|
+
```ruby
|
110
|
+
render_paginated DummyModel, each_serializer: CustomDummyModelSerializer, current_user: current_user
|
111
|
+
```
|
112
|
+
In serializer
|
113
|
+
```ruby
|
114
|
+
class CustomSerializer < ActiveModel::Serializer
|
115
|
+
def method
|
116
|
+
@instance_options[:current_user]
|
117
|
+
end
|
118
|
+
end
|
119
|
+
```
|
120
|
+
|
88
121
|
#### Custom formatters
|
89
122
|
A formatter is an object that defines the output of the render_paginated method. In case the application needs a different format for a request, it can be passed to the `render_paginated` method using the `formatter` option:
|
90
123
|
```ruby
|
@@ -117,25 +150,31 @@ If either Kaminari or will_paginate are required in the project, Wor::Paginate w
|
|
117
150
|
You can use the `be_paginated` matcher to test your endpoints. It also accepts the `with` chain method to receive a formatter.
|
118
151
|
|
119
152
|
You only need to add this in your rails_helper.rb
|
153
|
+
|
120
154
|
```ruby
|
121
155
|
# spec/rails_helper.rb
|
122
156
|
require 'wor/paginate/rspec'
|
123
157
|
```
|
158
|
+
|
124
159
|
And in your spec do
|
125
160
|
```ruby
|
126
161
|
# spec/controllers/your_controller.rb
|
127
162
|
describe YourController do
|
163
|
+
let(:response_body) do
|
164
|
+
ActiveSupport::JSON.decode(response.body) if response.present? && response.body.present?
|
165
|
+
end
|
166
|
+
|
128
167
|
describe '#index' do
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
end
|
168
|
+
subject(:http_request) { get :index }
|
169
|
+
|
170
|
+
it { expect(response_body).to be_paginated }
|
133
171
|
end
|
134
172
|
|
135
173
|
describe '#index_with_custom_formatter' do
|
174
|
+
subject(:http_request) { get :index_custom_formatter }
|
175
|
+
|
136
176
|
it 'checks that the response keys matches with the custom formatter' do
|
137
|
-
|
138
|
-
expect(response_body(response)).to be_paginated.with(CustomFormatter)
|
177
|
+
expect(response_body).to be_paginated.with(CustomFormatter)
|
139
178
|
end
|
140
179
|
end
|
141
180
|
end
|
@@ -149,12 +188,25 @@ end
|
|
149
188
|
4. Run rubocop lint (`bundle exec rubocop -R --format simple`)
|
150
189
|
5. Run rspec tests (`bundle exec rspec`)
|
151
190
|
6. Push your branch (`git push origin my-new-feature`)
|
152
|
-
7. Create a new Pull Request
|
191
|
+
7. Create a new Pull Request to `master` branch
|
192
|
+
|
193
|
+
## Releases
|
194
|
+
📢 [See what's changed in a recent version](https://github.com/Wolox/wor-paginate/releases)
|
153
195
|
|
154
196
|
## About ##
|
155
197
|
|
156
|
-
|
157
|
-
|
198
|
+
The current maintainers of this gem are :
|
199
|
+
* [Lucas Voboril](https://github.com/lucasVoboril)
|
200
|
+
* [Martín Mallea](https://github.com/mnmallea)
|
201
|
+
|
202
|
+
This project was developed by:
|
203
|
+
* [Hugo Farji](https://github.com/hdf1986)
|
204
|
+
* [Ignacio Coluccio](https://github.com/icoluccio)
|
205
|
+
* [Alan Halatian](https://github.com/alanhala)
|
206
|
+
|
207
|
+
At [Wolox](http://www.wolox.com.ar)
|
208
|
+
|
209
|
+
[![Wolox](https://raw.githubusercontent.com/Wolox/press-kit/master/logos/logo_banner.png)](http://www.wolox.com.ar)
|
158
210
|
|
159
211
|
## License
|
160
212
|
|
@@ -32,8 +32,9 @@ module Wor
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def serialized_content
|
35
|
-
|
36
|
-
|
35
|
+
if serializer.present?
|
36
|
+
return paginated_content.map { |item| serializer.new(item, options) }
|
37
|
+
end
|
37
38
|
if defined? ActiveModelSerializers::SerializableResource
|
38
39
|
ActiveModelSerializers::SerializableResource.new(paginated_content).as_json
|
39
40
|
else
|
@@ -12,6 +12,8 @@ module Wor
|
|
12
12
|
].freeze
|
13
13
|
|
14
14
|
def render_paginated(content, options = {})
|
15
|
+
return render_paginate_with_include(content, options) if includes?(options)
|
16
|
+
|
15
17
|
render json: paginate(content, options)
|
16
18
|
end
|
17
19
|
|
@@ -21,6 +23,10 @@ module Wor
|
|
21
23
|
formatter_class(options).new(adapter, options).format
|
22
24
|
end
|
23
25
|
|
26
|
+
def render_paginate_with_include(content, options)
|
27
|
+
render json: paginate(content, options), include: options[:include]
|
28
|
+
end
|
29
|
+
|
24
30
|
def formatter_class(options)
|
25
31
|
options[:formatter].presence || Formatter
|
26
32
|
end
|
@@ -42,6 +48,10 @@ module Wor
|
|
42
48
|
params[Config.per_page_param].to_i unless params[Config.per_page_param].nil?
|
43
49
|
end
|
44
50
|
|
51
|
+
def includes?(options)
|
52
|
+
!options[:include].nil?
|
53
|
+
end
|
54
|
+
|
45
55
|
def limit(options)
|
46
56
|
[
|
47
57
|
Config.max_limit,
|
data/lib/wor/paginate/version.rb
CHANGED
data/wor-paginate.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.version = Wor::Paginate::VERSION
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
10
|
s.date = Date.today
|
11
|
-
s.authors = ["
|
12
|
-
s.email = ["
|
11
|
+
s.authors = ["icoluccio", "mnmallea", "holywyvern", "lucasVoboril"]
|
12
|
+
s.email = ["ignacio.coluccio@wolox.com.ar", "martin.mallea@wolox.com.ar", "ramiro.rojo@wolox.com.ar", "lucas.voboril@wolox.com.ar"]
|
13
13
|
s.homepage = "https://github.com/Wolox/wor-paginate"
|
14
14
|
s.summary = "Simplified pagination for Rails API controllers"
|
15
15
|
s.description = "Wor::Paginate is a gem for Rails that simplifies pagination, particularly for controller methods, while standardizing JSON output for APIs. It's meant to work both as a standalone pagination gem and as an extra layer over Kaminari and will_paginate"
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wor-paginate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5a
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- hdf1986
|
8
7
|
- icoluccio
|
9
|
-
-
|
8
|
+
- mnmallea
|
9
|
+
- holywyvern
|
10
|
+
- lucasVoboril
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date:
|
14
|
+
date: 2019-09-13 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: railties
|
@@ -51,9 +52,10 @@ description: Wor::Paginate is a gem for Rails that simplifies pagination, partic
|
|
51
52
|
work both as a standalone pagination gem and as an extra layer over Kaminari and
|
52
53
|
will_paginate
|
53
54
|
email:
|
54
|
-
- hugo.farji@wolox.com.ar
|
55
55
|
- ignacio.coluccio@wolox.com.ar
|
56
|
-
-
|
56
|
+
- martin.mallea@wolox.com.ar
|
57
|
+
- ramiro.rojo@wolox.com.ar
|
58
|
+
- lucas.voboril@wolox.com.ar
|
57
59
|
executables: []
|
58
60
|
extensions: []
|
59
61
|
extra_rdoc_files: []
|
@@ -62,7 +64,6 @@ files:
|
|
62
64
|
- ".rubocop.yml"
|
63
65
|
- ".travis.yml"
|
64
66
|
- CHANGELOG.md
|
65
|
-
- Dangerfile
|
66
67
|
- Gemfile
|
67
68
|
- LICENSE.md
|
68
69
|
- README.md
|
@@ -85,6 +86,7 @@ files:
|
|
85
86
|
- lib/wor/paginate/paginate.rb
|
86
87
|
- lib/wor/paginate/rspec.rb
|
87
88
|
- lib/wor/paginate/version.rb
|
89
|
+
- pull_request_template.md
|
88
90
|
- wor-paginate.gemspec
|
89
91
|
homepage: https://github.com/Wolox/wor-paginate
|
90
92
|
licenses:
|
@@ -101,12 +103,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
103
|
version: '0'
|
102
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
105
|
requirements:
|
104
|
-
- - "
|
106
|
+
- - ">"
|
105
107
|
- !ruby/object:Gem::Version
|
106
|
-
version:
|
108
|
+
version: 1.3.1
|
107
109
|
requirements: []
|
108
|
-
|
109
|
-
rubygems_version: 2.7.6
|
110
|
+
rubygems_version: 3.0.2
|
110
111
|
signing_key:
|
111
112
|
specification_version: 4
|
112
113
|
summary: Simplified pagination for Rails API controllers
|
data/Dangerfile
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
# Sometimes it's a README fix, or something like that - which isn't relevant for
|
2
|
-
# including in a project's CHANGELOG for example
|
3
|
-
declared_trivial = github.pr_title.include? "#trivial"
|
4
|
-
gemfile_changed = git.deleted_files.include?('Gemfile')
|
5
|
-
gemfile_lock_changed = git.deleted_files.include?('Gemfile.lock')
|
6
|
-
|
7
|
-
# Make it more obvious that a PR is a work in progress and shouldn't be merged yet
|
8
|
-
warn("PR is classed as Work in Progress") if github.pr_title.include? "[WIP]"
|
9
|
-
|
10
|
-
# Warn when there is a big PR with more than 500 lines
|
11
|
-
warn("Big PR. If it's possible try to reduce this into smaller PR's") if git.lines_of_code > 500
|
12
|
-
|
13
|
-
# Warn when a PR is clased as work in progress
|
14
|
-
warn "PR is classed as Work in Progress" if github.pr_title.include? "[WIP]"
|
15
|
-
|
16
|
-
# Don't let testing shortcuts get into master by accident
|
17
|
-
fail("fdescribe left in tests") if `grep -r fdescribe specs/ `.length > 1
|
18
|
-
fail("fit left in tests") if `grep -r fit specs/ `.length > 1
|
19
|
-
|
20
|
-
# Ensure there's a summary on the pull request description
|
21
|
-
fail "Please provide a summary in the Pull Request description" if github.pr_body.length < 5
|
22
|
-
|
23
|
-
# Ensures that the PR is mergeable
|
24
|
-
can_merge = github.pr_json["mergeable"]
|
25
|
-
fail("This PR cannot be merged yet. Please fix the conflicts with the base branch", sticky: false) unless can_merge
|
26
|
-
|
27
|
-
# It fails when TODO's are present
|
28
|
-
todoist.message = "Please fix all TODOS"
|
29
|
-
todoist.fail_for_todos
|
30
|
-
|
31
|
-
# Check for changes in the CHANGELOG.md if the pr isn't trivial
|
32
|
-
unless declared_trivial
|
33
|
-
[
|
34
|
-
'CHANGELOG.md'
|
35
|
-
].each do |file_who_needs_change|
|
36
|
-
fail("#{file_who_needs_change} needs to be changed") unless git.modified_files.include?(file_who_needs_change)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
# Fails when an important file is deleted or renamed
|
40
|
-
[
|
41
|
-
'wor-paginate-gemspec',
|
42
|
-
'README.md',
|
43
|
-
'CHANGELOG.md',
|
44
|
-
'.gitignore',
|
45
|
-
'.travis.yml',
|
46
|
-
'.rubocop.yml'
|
47
|
-
].each do |protected_file|
|
48
|
-
fail("#{protected_file} file shouldn't be deleted or renamed") if git.deleted_files.include?(protected_file) || git.renamed_files.include?(protected_file)
|
49
|
-
end
|
50
|
-
|
51
|
-
# Fails when a dangerous file is uploaded
|
52
|
-
[
|
53
|
-
'.ruby-version',
|
54
|
-
'Gemfile.lock',
|
55
|
-
].each do |protected_file|
|
56
|
-
fail("#{protected_file} file shouldn't be added") if git.added_files.include?(protected_file)
|
57
|
-
end
|
58
|
-
|
59
|
-
# Removes placeholder line
|
60
|
-
# Danger::Changelog.configure do |config|
|
61
|
-
# config.placeholder_line = nil
|
62
|
-
# end
|
63
|
-
|
64
|
-
# Check that bundle install where ran
|
65
|
-
# if gemfile_changed && !gemfile_lock_changed
|
66
|
-
# message = 'Changes were made to Gemfile, but not to Gemfile.lock';
|
67
|
-
# idea = 'Perhaps you need to run `bundle install`?';
|
68
|
-
# warn(`${message} - <i>${idea}</i>`);
|
69
|
-
# end
|