paginate-responder 1.7.0 → 1.8.0

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
- SHA1:
3
- metadata.gz: 7a6cc9eda71db6450ff7bd5607db1662a6611382
4
- data.tar.gz: 90c046db266b6720c601edeffbcac50dc01a5cc9
2
+ SHA256:
3
+ metadata.gz: 2f44ce9f98a85e03ae656db512564e7d9ce3263c1af1e4ec4d7c484a7f3a29f2
4
+ data.tar.gz: 7c66f7d57534805c6ed6109072e55e5e42ac816e5c4e2454e5c4788c0d22002b
5
5
  SHA512:
6
- metadata.gz: 7c932b5edae57215e25e82d40514db777cdfc10f6c251357e51181062288d2def594b232a39c8828df67fca83ea98e5b8f5d81ada42cd8df6d2b839a84cff769
7
- data.tar.gz: 3740ca577f36090214e750bd04701d334653cfb0d7936b949d3dffb3e389584486d965379ca890e1e110ee0b0463ae7b9bbd16fae41c810acc933821463334c4
6
+ metadata.gz: 3288c6abccc463b074bcf01066ea71b1a3e80351a396002bd60d23f8e30f3cd184038ebc0d63d809ddd782617719d7f1a720142ce3338f1d0e166a8295b03d79
7
+ data.tar.gz: a8a9f0672d0a1bff70dc16809d20c1f8f3566d2859dc9222b17def372eff1f4a3e13614232569244b1ceeafed19bbcee2f5bea59d62d5f5265cbb5d36aa57f54
data/.travis.yml CHANGED
@@ -1,26 +1,58 @@
1
- sudo: false
2
- dist: trusty
1
+ dist: xenial
3
2
  language: ruby
4
3
  rvm:
5
- - '2.4.1'
6
- - '2.3.4'
7
- - '2.2.7'
8
- - '2.1.10'
4
+ - 2.6.1
5
+ - 2.5.3
6
+ - 2.4.5
7
+ - 2.3.8
8
+ before_install:
9
+ - rvm --force gemset delete global
10
+ - gem install bundler -v '~> 1.17'
9
11
  env:
10
- - GEM=will_paginate
11
- - GEM=kaminari
12
+ - GEM=will_paginate
13
+ - GEM=kaminari
14
+ - GEM=pagy
12
15
  gemfile:
13
- - gemfiles/rails_4_2.gemfile
14
- - gemfiles/rails_5_0.gemfile
15
- - gemfiles/rails_5_1.gemfile
16
- - gemfiles/rails_head.gemfile
17
- matrix:
16
+ - gemfiles/rails_4_2.gemfile
17
+ - gemfiles/rails_5_0.gemfile
18
+ - gemfiles/rails_5_1.gemfile
19
+ - gemfiles/rails_5_2.gemfile
20
+ - gemfiles/rails_head.gemfile
21
+ jobs:
18
22
  exclude:
19
- - rvm: '2.1.10'
20
- gemfile: gemfiles/rails_5_0.gemfile
21
- - rvm: '2.1.10'
22
- gemfile: gemfiles/rails_5_1.gemfile
23
- - rvm: '2.1.10'
24
- gemfile: gemfiles/rails_head.gemfile
23
+ - rvm: 2.6.1
24
+ gemfile: gemfiles/rails_4_2.gemfile
25
+ - rvm: 2.1.10
26
+ gemfile: gemfiles/rails_5_0.gemfile
27
+ - rvm: 2.1.10
28
+ gemfile: gemfiles/rails_5_1.gemfile
29
+ - rvm: 2.1.10
30
+ gemfile: gemfiles/rails_5_2.gemfile
31
+ - rvm: 2.4.5
32
+ gemfile: gemfiles/rails_head.gemfile
33
+ - rvm: 2.3.8
34
+ gemfile: gemfiles/rails_head.gemfile
35
+ - rvm: 2.2.10
36
+ gemfile: gemfiles/rails_head.gemfile
37
+ - rvm: 2.1.10
38
+ gemfile: gemfiles/rails_head.gemfile
39
+ - rvm: 2.2.10
40
+ env: GEM=pagy
41
+ - rvm: 2.1.10
42
+ env: GEM=pagy
25
43
  allow_failures:
26
44
  - gemfile: gemfiles/rails_head.gemfile
45
+ include:
46
+ - stage: Release
47
+ rvm: 2.6.1
48
+ env: []
49
+ script: skip
50
+ install: skip
51
+ deploy:
52
+ provider: rubygems
53
+ api_key:
54
+ secure: MgeXelR7uhiEvC7dqRzV7e6SbWAMG7TvEquFvqIEh0osAbjdV2UKLPGoFHhoP3WTrcPqxUw9HYr0uBsxm5Oj+wsdIT1VSCojVw0BwTIE+rpFFE5JdZdQr5217vAFJn4H8ddareh5E2dyFUXWzlH2w0+75DZd33NAO5LfN2GXsAc=
55
+ gem: paginate-responder
56
+ on:
57
+ tags: true
58
+ repo: jgraichen/paginate-responder
data/Appraisals CHANGED
@@ -1,13 +1,29 @@
1
1
  appraise "rails-4-2" do
2
2
  gem 'rails', '~> 4.2.0'
3
+
4
+ # Fix version conflict in active_record
5
+ gem 'sqlite3', '~> 1.3.6'
3
6
  end
4
7
 
5
8
  appraise "rails-5-0" do
6
9
  gem 'rails', '~> 5.0.0'
10
+
11
+ # Fix version conflict in active_record
12
+ gem 'sqlite3', '~> 1.3.6'
7
13
  end
8
14
 
9
15
  appraise "rails-5-1" do
10
16
  gem 'rails', '~> 5.1.0'
17
+
18
+ # Fix version conflict in active_record
19
+ gem 'sqlite3', '~> 1.3.6'
20
+ end
21
+
22
+ appraise "rails-5-2" do
23
+ gem 'rails', '~> 5.2.0'
24
+
25
+ # Fix version conflict in active_record
26
+ gem 'sqlite3', '~> 1.3.6'
11
27
  end
12
28
 
13
29
  appraise "rails-head" do
data/CHANGELOG.md CHANGED
@@ -1,4 +1,18 @@
1
1
  # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## 1.8.0 - 2019-02-19
10
+ ### Added
11
+ * Support for pagination using `pagy` gem (#14)
12
+
13
+ ### Fixed
14
+ * sqlite3 version conflict in active_record (#15)
15
+ * Invalid ?page parameter could cause exceptions (#16)
2
16
 
3
17
  ## 1.7.0
4
18
 
data/Gemfile CHANGED
@@ -2,3 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in paginate-responder.gemspec
4
4
  gemspec
5
+
6
+ # Fix version conflict in active_record
7
+ gem 'sqlite3', '~> 1.3.6'
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # Paginate::Responder
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/paginate-responder.png)](http://badge.fury.io/rb/paginate-responder)
4
- [![Build Status](https://travis-ci.org/jgraichen/paginate-responder.png?branch=master)](https://travis-ci.org/jgraichen/paginate-responder)
5
- [![Code Climate](https://codeclimate.com/github/jgraichen/paginate-responder.png)](https://codeclimate.com/github/jgraichen/paginate-responder)
3
+ [![Gem](https://img.shields.io/gem/v/paginate-responder.svg)](https://rubygems.org/gems/paginate-responder)
4
+ [![Build Status](https://travis-ci.org/jgraichen/paginate-responder.svg?branch=master)](https://travis-ci.org/jgraichen/paginate-responder)
5
+ [![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/jgraichen/paginate-responder.svg)](https://codeclimate.com/github/jgraichen/paginate-responder)
6
+
6
7
 
7
8
  A Rails pagination responder with link header support.
8
9
 
@@ -21,8 +22,9 @@ Or install it yourself as:
21
22
  $ gem install paginate-responder
22
23
 
23
24
  You will also need a pagination gem. `PaginateResponder` comes with adapters for
24
- * [will_paginate](https://github.com/mislav/will_paginate) and
25
- * [kaminari](https://github.com/amatsuda/kaminari).
25
+ * [will_paginate](https://github.com/mislav/will_paginate),
26
+ * [kaminari](https://github.com/amatsuda/kaminari), and
27
+ * [pagy](https://github.com/ddnexus/pagy).
26
28
 
27
29
  It is recommended to use only one pagination gem at once.
28
30
 
@@ -51,13 +53,13 @@ end
51
53
  `PaginateResponder` will add the following link headers to
52
54
  non HTML responses:
53
55
 
54
- * *first* First page's URL.
55
- * *last* Last page's URL.
56
- * *next* Next page's URL.
57
- * *prev* Previous page's URL.
56
+ * `first` First page's URL.
57
+ * `last` Last page's URL.
58
+ * `next` Next page's URL.
59
+ * `prev` Previous page's URL.
58
60
 
59
- Next and previous page links will not be added if current
60
- page is first or last page.
61
+ `next` and `prev` page links will not be added if current
62
+ page is `first` or `last` page.
61
63
 
62
64
  Also a `X-Total-Pages` header will be added with the total
63
65
  number of pages if available and a `X-Total-Count` header
@@ -70,7 +72,7 @@ You can override the page detection by creating a method
70
72
  `page` in your controller that returns the page index as
71
73
  a fixnum:
72
74
 
73
- ```
75
+ ```ruby
74
76
  class ApplicationController
75
77
  def page
76
78
  params[:seite].to_i # seite means page in German
@@ -80,7 +82,7 @@ end
80
82
 
81
83
  Same goes for `per_page` and `max_per_page`:
82
84
 
83
- ```
85
+ ```ruby
84
86
  class ApplicationController
85
87
  def per_page
86
88
  10
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
+ gem "sqlite3", "~> 1.3.6"
5
6
  gem "rails", "~> 4.2.0"
6
7
 
7
8
  gemspec path: "../"
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
+ gem "sqlite3", "~> 1.3.6"
5
6
  gem "rails", "~> 5.0.0"
6
7
 
7
8
  gemspec path: "../"
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
+ gem "sqlite3", "~> 1.3.6"
5
6
  gem "rails", "~> 5.1.0"
6
7
 
7
8
  gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sqlite3", "~> 1.3.6"
6
+ gem "rails", "~> 5.2.0"
7
+
8
+ gemspec path: "../"
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
+ gem "sqlite3", "~> 1.3.6"
5
6
  gem "rails", github: "rails/rails"
6
7
 
7
8
  gemspec path: "../"
@@ -9,4 +9,5 @@ module PaginateResponder
9
9
  require 'paginate-responder/base'
10
10
  require 'paginate-responder/will_paginate_adapter'
11
11
  require 'paginate-responder/kaminari_adapter'
12
+ require 'paginate-responder/pagy_adapter'
12
13
  end
@@ -56,6 +56,8 @@ module PaginateResponder
56
56
 
57
57
  def cast_page(page)
58
58
  Integer(page)
59
+ rescue ArgumentError
60
+ 1
59
61
  end
60
62
 
61
63
  def per_page
@@ -0,0 +1,51 @@
1
+ module PaginateResponder
2
+ #
3
+ # Pagination adapter for pagy.
4
+ #
5
+ class PagyAdapter < Base
6
+ def paginate
7
+ self.pagy, self.pagy_resource = controller.send(self.class.pagy_method(resource), resource, page: page, items: per_page)
8
+ pagy_resource
9
+ end
10
+
11
+ def total_pages
12
+ pagy.pages
13
+ end
14
+
15
+ def total_count
16
+ pagy.count
17
+ end
18
+
19
+ def default_per_page
20
+ Pagy::VARS[:items]
21
+ end
22
+
23
+ def default_max_per_page
24
+ Pagy::VARS[:max_items] || BigDecimal::INFINITY
25
+ end
26
+
27
+ def paginate!
28
+ paginate.tap do
29
+ update
30
+ end
31
+ end
32
+
33
+ class << self
34
+ def suitable?(resource, responder)
35
+ responder.controller.respond_to?(pagy_method(resource), true)
36
+ end
37
+
38
+ def pagy_method(resource)
39
+ %i[limit offset].all? { |model_method| resource.respond_to?(model_method) } ? :pagy : :pagy_array
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ attr_accessor :pagy, :pagy_resource
46
+ end
47
+
48
+ if defined?(:Pagy)
49
+ ::Responders::PaginateResponder.register PagyAdapter
50
+ end
51
+ end
@@ -1,7 +1,7 @@
1
1
  module PaginateResponder
2
2
  module VERSION
3
3
  MAJOR = 1
4
- MINOR = 7
4
+ MINOR = 8
5
5
  PATCH = 0
6
6
  STAGE = nil
7
7
 
@@ -24,13 +24,14 @@ Gem::Specification.new do |gem|
24
24
  gem.add_development_dependency 'activerecord', '>= 3.2.0'
25
25
  gem.add_development_dependency 'appraisal'
26
26
  gem.add_development_dependency 'kaminari'
27
+ gem.add_development_dependency 'pagy'
27
28
  gem.add_development_dependency 'pry'
28
29
  gem.add_development_dependency 'pry-byebug'
29
30
  gem.add_development_dependency 'rake'
30
31
  gem.add_development_dependency 'responders'
31
32
  gem.add_development_dependency 'rspec'
32
33
  gem.add_development_dependency 'rspec-rails'
33
- gem.add_development_dependency 'sqlite3'
34
+ gem.add_development_dependency 'sqlite3', '~> 1.3.6'
34
35
  gem.add_development_dependency 'will_paginate'
35
36
  gem.add_development_dependency 'test-unit'
36
37
  end
@@ -2,7 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe Responders::PaginateResponder, type: :controller do
4
4
  case $gem
5
- when 'will_paginate'
5
+ when 'will_paginate',
6
+ 'pagy'
6
7
  let(:array_resource) do
7
8
  ('AA'..'zz').to_a
8
9
  end
@@ -39,6 +40,22 @@ RSpec.describe Responders::PaginateResponder, type: :controller do
39
40
  it { expect(json).to eq (51..100).to_a }
40
41
  end
41
42
 
43
+ describe '?page empty' do
44
+ let(:params) { super().merge page: '' }
45
+
46
+ it 'responds with first page' do
47
+ expect(json).to eq (1..50).to_a
48
+ end
49
+ end
50
+
51
+ describe '?page invalid' do
52
+ let(:params) { super().merge page: 'foobar' }
53
+
54
+ it 'responds with first page' do
55
+ expect(json).to eq (1..50).to_a
56
+ end
57
+ end
58
+
42
59
  describe '?per_page' do
43
60
  let(:params) { super().merge per_page: 10 }
44
61
 
data/spec/spec_helper.rb CHANGED
@@ -37,6 +37,15 @@ case $gem
37
37
  config.default_per_page = 50
38
38
  config.max_per_page = 50
39
39
  end
40
+ when 'pagy'
41
+ require 'pagy'
42
+ require 'pagy/extras/array'
43
+ require 'pagy/extras/items'
44
+
45
+ TestController.include(Pagy::Backend)
46
+
47
+ Pagy::VARS[:items] = 50
48
+ Pagy::VARS[:max_items] = 50
40
49
  end
41
50
 
42
51
  RSpec.configure do |config|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paginate-responder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-02 00:00:00.000000000 Z
11
+ date: 2019-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack-link_headers
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pagy
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: pry
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -168,16 +182,16 @@ dependencies:
168
182
  name: sqlite3
169
183
  requirement: !ruby/object:Gem::Requirement
170
184
  requirements:
171
- - - ">="
185
+ - - "~>"
172
186
  - !ruby/object:Gem::Version
173
- version: '0'
187
+ version: 1.3.6
174
188
  type: :development
175
189
  prerelease: false
176
190
  version_requirements: !ruby/object:Gem::Requirement
177
191
  requirements:
178
- - - ">="
192
+ - - "~>"
179
193
  - !ruby/object:Gem::Version
180
- version: '0'
194
+ version: 1.3.6
181
195
  - !ruby/object:Gem::Dependency
182
196
  name: will_paginate
183
197
  requirement: !ruby/object:Gem::Requirement
@@ -224,10 +238,12 @@ files:
224
238
  - gemfiles/rails_4_2.gemfile
225
239
  - gemfiles/rails_5_0.gemfile
226
240
  - gemfiles/rails_5_1.gemfile
241
+ - gemfiles/rails_5_2.gemfile
227
242
  - gemfiles/rails_head.gemfile
228
243
  - lib/paginate-responder.rb
229
244
  - lib/paginate-responder/base.rb
230
245
  - lib/paginate-responder/kaminari_adapter.rb
246
+ - lib/paginate-responder/pagy_adapter.rb
231
247
  - lib/paginate-responder/version.rb
232
248
  - lib/paginate-responder/will_paginate_adapter.rb
233
249
  - lib/responders/paginate_responder.rb
@@ -256,7 +272,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
256
272
  version: '0'
257
273
  requirements: []
258
274
  rubyforge_project:
259
- rubygems_version: 2.6.11
275
+ rubygems_version: 2.7.7
260
276
  signing_key:
261
277
  specification_version: 4
262
278
  summary: A Rails pagination responder with link header support.