api-pagination 5.0.0 → 7.0.0
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/lib/api-pagination/configuration.rb +35 -30
- data/lib/api-pagination/hooks.rb +8 -8
- data/lib/api-pagination/railtie.rb +2 -2
- data/lib/api-pagination/version.rb +2 -2
- data/lib/api-pagination.rb +26 -23
- data/lib/grape/pagination.rb +17 -17
- data/lib/rails/pagination.rb +11 -13
- metadata +12 -61
- data/spec/active_record_spec.rb +0 -50
- data/spec/api-pagination_spec.rb +0 -76
- data/spec/grape_spec.rb +0 -165
- data/spec/rails_spec.rb +0 -312
- data/spec/sequel_spec.rb +0 -30
- data/spec/spec_helper.rb +0 -39
- data/spec/support/active_record/foo.rb +0 -3
- data/spec/support/active_record/schema.rb +0 -5
- data/spec/support/numbers_api.rb +0 -41
- data/spec/support/numbers_controller.rb +0 -103
- data/spec/support/shared_examples/existing_headers.rb +0 -14
- data/spec/support/shared_examples/first_page.rb +0 -30
- data/spec/support/shared_examples/last_page.rb +0 -31
- data/spec/support/shared_examples/middle_page.rb +0 -22
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6e0fe91ed44af366ebdeb56315b67d307d70b4bf9885ea8d64573a20b77d7782
|
|
4
|
+
data.tar.gz: 8efc6d6ebee6ce84b2c14117858e8168c6eecf75f178172e58f6044fe63c86ac
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1cb85390ee04fe7c8f696230d17c7008112c232ed22e96e45963057e05c4f9b60c7923b9e94de7b6362523110e04c0e11f92e55c94edf2423fa0c59ea99f46f2
|
|
7
|
+
data.tar.gz: 717a43cb3df244ec6164be3340f215f9974ce2355336ff0aa5656ad345e4729057ad066ade421a2c041e6bdaf4cffed8acdcefb3e41e4b9f780b578b31ad6229
|
|
@@ -17,15 +17,15 @@ module ApiPagination
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def initialize
|
|
20
|
-
@total_header
|
|
21
|
-
@per_page_header =
|
|
22
|
-
@page_header
|
|
23
|
-
@include_total
|
|
24
|
-
@base_url
|
|
20
|
+
@total_header = "Total"
|
|
21
|
+
@per_page_header = "Per-Page"
|
|
22
|
+
@page_header = nil
|
|
23
|
+
@include_total = true
|
|
24
|
+
@base_url = nil
|
|
25
25
|
@response_formats = [:json, :xml]
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
[
|
|
28
|
+
["page", "per_page"].each do |param_name|
|
|
29
29
|
method_name = "#{param_name}_param"
|
|
30
30
|
instance_variable_name = "@#{method_name}"
|
|
31
31
|
|
|
@@ -37,7 +37,7 @@ module ApiPagination
|
|
|
37
37
|
|
|
38
38
|
if instance_variable_get(instance_variable_name).nil?
|
|
39
39
|
# use :page & :per_page by default
|
|
40
|
-
instance_variable_set(instance_variable_name,
|
|
40
|
+
instance_variable_set(instance_variable_name, lambda { |p| p[param_name.to_sym] })
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
instance_variable_get(instance_variable_name).call(params)
|
|
@@ -45,7 +45,7 @@ module ApiPagination
|
|
|
45
45
|
|
|
46
46
|
define_method "#{method_name}=" do |param|
|
|
47
47
|
if param.is_a?(Symbol) || param.is_a?(String)
|
|
48
|
-
instance_variable_set(instance_variable_name,
|
|
48
|
+
instance_variable_set(instance_variable_name, lambda { |params| params[param] })
|
|
49
49
|
else
|
|
50
50
|
raise ArgumentError, "Cannot set page_param option"
|
|
51
51
|
end
|
|
@@ -78,24 +78,24 @@ module ApiPagination
|
|
|
78
78
|
def set_paginator
|
|
79
79
|
conditions = [defined?(Pagy), defined?(Kaminari), defined?(WillPaginate::CollectionMethods)]
|
|
80
80
|
if conditions.compact.size > 1
|
|
81
|
-
Kernel.warn
|
|
82
|
-
Warning: api-pagination relies on Pagy, Kaminari, or WillPaginate, but more than
|
|
83
|
-
one are currently active. If possible, you should remove one or the other. If
|
|
84
|
-
you can't, you _must_ configure api-pagination on your own. For example:
|
|
85
|
-
|
|
86
|
-
ApiPagination.configure do |config|
|
|
87
|
-
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
You should also configure Kaminari to use a different `per_page` method name as
|
|
91
|
-
using these gems together causes a conflict; some information can be found at
|
|
92
|
-
https://github.com/activeadmin/activeadmin/wiki/How-to-work-with-will_paginate
|
|
93
|
-
|
|
94
|
-
Kaminari.configure do |config|
|
|
95
|
-
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
WARNING
|
|
81
|
+
Kernel.warn <<~WARNING
|
|
82
|
+
Warning: api-pagination relies on Pagy, Kaminari, or WillPaginate, but more than
|
|
83
|
+
one are currently active. If possible, you should remove one or the other. If
|
|
84
|
+
you can't, you _must_ configure api-pagination on your own. For example:
|
|
85
|
+
|
|
86
|
+
ApiPagination.configure do |config|
|
|
87
|
+
config.paginator = :kaminari
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
You should also configure Kaminari to use a different `per_page` method name as
|
|
91
|
+
using these gems together causes a conflict; some information can be found at
|
|
92
|
+
https://github.com/activeadmin/activeadmin/wiki/How-to-work-with-will_paginate
|
|
93
|
+
|
|
94
|
+
Kaminari.configure do |config|
|
|
95
|
+
config.page_method_name = :per_page_kaminari
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
WARNING
|
|
99
99
|
elsif defined?(Pagy)
|
|
100
100
|
use_pagy
|
|
101
101
|
elsif defined?(Kaminari)
|
|
@@ -110,14 +110,19 @@ WARNING
|
|
|
110
110
|
end
|
|
111
111
|
|
|
112
112
|
def use_kaminari
|
|
113
|
-
require
|
|
113
|
+
require "kaminari/models/array_extension"
|
|
114
114
|
@paginator = :kaminari
|
|
115
115
|
end
|
|
116
116
|
|
|
117
117
|
def use_will_paginate
|
|
118
118
|
WillPaginate::CollectionMethods.module_eval do
|
|
119
|
-
def first_page?
|
|
120
|
-
|
|
119
|
+
def first_page?
|
|
120
|
+
!previous_page
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def last_page?
|
|
124
|
+
!next_page
|
|
125
|
+
end
|
|
121
126
|
end
|
|
122
127
|
|
|
123
128
|
@paginator = :will_paginate
|
|
@@ -132,6 +137,6 @@ WARNING
|
|
|
132
137
|
def config
|
|
133
138
|
@config ||= Configuration.new
|
|
134
139
|
end
|
|
135
|
-
|
|
140
|
+
alias_method :configuration, :config
|
|
136
141
|
end
|
|
137
142
|
end
|
data/lib/api-pagination/hooks.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
begin; require
|
|
1
|
+
begin; require "grape"; rescue LoadError; end
|
|
2
2
|
if defined?(Grape::API)
|
|
3
|
-
require
|
|
3
|
+
require "grape/pagination"
|
|
4
4
|
|
|
5
|
-
klass = if Grape::VERSION >=
|
|
5
|
+
klass = if Grape::VERSION >= "1.2.0" || defined?(Grape::API::Instance)
|
|
6
6
|
Grape::API::Instance
|
|
7
7
|
else
|
|
8
8
|
Grape::API
|
|
@@ -11,12 +11,12 @@ if defined?(Grape::API)
|
|
|
11
11
|
klass.send(:include, Grape::Pagination)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
begin; require
|
|
15
|
-
begin; require
|
|
16
|
-
begin; require
|
|
14
|
+
begin; require "pagy"; rescue LoadError; end
|
|
15
|
+
begin; require "kaminari"; rescue LoadError; end
|
|
16
|
+
begin; require "will_paginate"; rescue LoadError; end
|
|
17
17
|
|
|
18
18
|
unless defined?(Pagy) || defined?(Kaminari) || defined?(WillPaginate::CollectionMethods)
|
|
19
|
-
Kernel.warn <<-WARNING.gsub(/^\s{4}/,
|
|
19
|
+
Kernel.warn <<-WARNING.gsub(/^\s{4}/, "")
|
|
20
20
|
Warning: api-pagination relies on either Pagy, Kaminari, or WillPaginate.
|
|
21
21
|
Please install a paginator by adding one of the following to your Gemfile:
|
|
22
22
|
|
|
@@ -39,5 +39,5 @@ if defined?(Rails)
|
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
require
|
|
42
|
+
require "api-pagination/railtie"
|
|
43
43
|
end
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "rails/railtie"
|
|
2
2
|
|
|
3
3
|
module ApiPagination
|
|
4
4
|
class Railtie < ::Rails::Railtie
|
|
5
5
|
initializer :api_pagination do
|
|
6
6
|
ActiveSupport.on_load(:action_controller) do
|
|
7
|
-
require
|
|
7
|
+
require "rails/pagination"
|
|
8
8
|
|
|
9
9
|
klass = if Rails::VERSION::MAJOR >= 5 || defined?(ActionController::API)
|
|
10
10
|
ActionController::API
|
data/lib/api-pagination.rb
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
1
|
+
require "api-pagination/configuration"
|
|
2
|
+
require "api-pagination/version"
|
|
3
3
|
|
|
4
4
|
module ApiPagination
|
|
5
5
|
class << self
|
|
6
6
|
def paginate(collection, options = {})
|
|
7
|
-
options[:page]
|
|
8
|
-
options[:page]
|
|
7
|
+
options[:page] = options[:page].to_i
|
|
8
|
+
options[:page] = 1 if options[:page] <= 0
|
|
9
9
|
options[:per_page] = options[:per_page].to_i
|
|
10
10
|
|
|
11
11
|
case ApiPagination.config.paginator
|
|
@@ -26,10 +26,10 @@ module ApiPagination
|
|
|
26
26
|
{}.tap do |pages|
|
|
27
27
|
unless collection.first_page?
|
|
28
28
|
pages[:first] = 1
|
|
29
|
-
pages[:prev]
|
|
29
|
+
pages[:prev] = collection.current_page - 1
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
if !(collection.last_page? || (ApiPagination.config.paginator == :kaminari && collection.out_of_range?))
|
|
33
33
|
pages[:last] = collection.total_pages if ApiPagination.config.include_total
|
|
34
34
|
pages[:next] = collection.current_page + 1
|
|
35
35
|
end
|
|
@@ -38,46 +38,49 @@ module ApiPagination
|
|
|
38
38
|
|
|
39
39
|
def total_from(collection)
|
|
40
40
|
case ApiPagination.config.paginator
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
when :pagy then collection.count.to_s
|
|
42
|
+
when :kaminari then collection.total_count.to_s
|
|
43
|
+
when :will_paginate then collection.total_entries.to_s
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
private
|
|
48
48
|
|
|
49
49
|
def paginate_with_pagy(collection, options)
|
|
50
|
-
if Pagy
|
|
51
|
-
options[:per_page] = Pagy
|
|
50
|
+
if Pagy.options[:max_per_page] && options[:per_page] > Pagy.options[:max_per_page]
|
|
51
|
+
options[:per_page] = Pagy.options[:max_per_page]
|
|
52
52
|
elsif options[:per_page] <= 0
|
|
53
|
-
options[:per_page] = Pagy
|
|
53
|
+
options[:per_page] = Pagy.options[:limit]
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
pagy = pagy_from(collection, options)
|
|
57
57
|
collection = if collection.respond_to?(:offset) && collection.respond_to?(:limit)
|
|
58
|
-
collection.offset(pagy.offset).limit(pagy.
|
|
58
|
+
collection.offset(pagy.offset).limit(pagy.limit)
|
|
59
59
|
else
|
|
60
|
-
collection[pagy.offset, pagy.
|
|
60
|
+
collection[pagy.offset, pagy.limit]
|
|
61
61
|
end
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
[collection, pagy]
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
def pagy_from(collection, options)
|
|
67
|
-
if options[:count]
|
|
68
|
-
|
|
67
|
+
count = if options[:count]
|
|
68
|
+
options[:count]
|
|
69
69
|
else
|
|
70
|
-
|
|
70
|
+
collection.is_a?(Array) ? collection.count : collection.count(:all)
|
|
71
71
|
end
|
|
72
72
|
|
|
73
|
-
Pagy.
|
|
73
|
+
# Pagy 9.x requires keyword arguments
|
|
74
|
+
# Use explicit keyword argument syntax to avoid Ruby version quirks
|
|
75
|
+
pagy_options = {count: count, limit: options[:per_page], page: options[:page]}
|
|
76
|
+
Pagy::Offset.new(**pagy_options)
|
|
74
77
|
end
|
|
75
78
|
|
|
76
79
|
def pagy_pages_from(pagy)
|
|
77
80
|
{}.tap do |pages|
|
|
78
81
|
unless pagy.page == 1
|
|
79
82
|
pages[:first] = 1
|
|
80
|
-
pages[:prev]
|
|
83
|
+
pages[:prev] = pagy.previous
|
|
81
84
|
end
|
|
82
85
|
|
|
83
86
|
unless pagy.page == pagy.pages
|
|
@@ -105,11 +108,11 @@ module ApiPagination
|
|
|
105
108
|
options[:per_page] = default_per_page_for_will_paginate(collection)
|
|
106
109
|
end
|
|
107
110
|
|
|
108
|
-
collection = if defined?(Sequel::Dataset) && collection.
|
|
111
|
+
collection = if defined?(Sequel::Dataset) && collection.is_a?(Sequel::Dataset)
|
|
109
112
|
collection.paginate(options[:page], options[:per_page])
|
|
110
113
|
else
|
|
111
114
|
supported_options = [:page, :per_page, :total_entries]
|
|
112
|
-
options = options.dup.keep_if { |k,v| supported_options.include?(k.to_sym) }
|
|
115
|
+
options = options.dup.keep_if { |k, v| supported_options.include?(k.to_sym) }
|
|
113
116
|
collection.paginate(options)
|
|
114
117
|
end
|
|
115
118
|
|
|
@@ -139,4 +142,4 @@ module ApiPagination
|
|
|
139
142
|
end
|
|
140
143
|
end
|
|
141
144
|
|
|
142
|
-
require
|
|
145
|
+
require "api-pagination/hooks"
|
data/lib/grape/pagination.rb
CHANGED
|
@@ -6,32 +6,32 @@ module Grape
|
|
|
6
6
|
per_page = ApiPagination.config.per_page_param(params) || route_setting(:per_page)
|
|
7
7
|
|
|
8
8
|
options = {
|
|
9
|
-
:
|
|
10
|
-
:
|
|
9
|
+
page: ApiPagination.config.page_param(params),
|
|
10
|
+
per_page: [per_page, route_setting(:max_per_page)].compact.min
|
|
11
11
|
}
|
|
12
12
|
collection, pagy = ApiPagination.paginate(collection, options)
|
|
13
13
|
|
|
14
|
-
links = (header[
|
|
15
|
-
url
|
|
14
|
+
links = (header["Link"] || "").split(",").map(&:strip)
|
|
15
|
+
url = request.url.sub(/\?.*$/, "")
|
|
16
16
|
pages = ApiPagination.pages_from(pagy || collection, options)
|
|
17
17
|
|
|
18
18
|
pages.each do |k, v|
|
|
19
19
|
old_params = Rack::Utils.parse_nested_query(request.query_string)
|
|
20
|
-
new_params = old_params.merge(
|
|
20
|
+
new_params = old_params.merge("page" => v)
|
|
21
21
|
links << %(<#{url}?#{new_params.to_param}>; rel="#{k}")
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
total_header
|
|
24
|
+
total_header = ApiPagination.config.total_header
|
|
25
25
|
per_page_header = ApiPagination.config.per_page_header
|
|
26
|
-
page_header
|
|
27
|
-
include_total
|
|
26
|
+
page_header = ApiPagination.config.page_header
|
|
27
|
+
include_total = ApiPagination.config.include_total
|
|
28
28
|
|
|
29
|
-
header
|
|
30
|
-
header total_header,
|
|
29
|
+
header "Link", links.join(", ") unless links.empty?
|
|
30
|
+
header total_header, ApiPagination.total_from(pagy || collection).to_s if include_total
|
|
31
31
|
header per_page_header, options[:per_page].to_s
|
|
32
|
-
header page_header,
|
|
32
|
+
header page_header, options[:page].to_s unless page_header.nil?
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
collection
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
|
|
@@ -44,11 +44,11 @@ module Grape
|
|
|
44
44
|
per_page_values = enforce_max_per_page ? 0..options[:max_per_page] : nil
|
|
45
45
|
|
|
46
46
|
params do
|
|
47
|
-
optional :page,
|
|
48
|
-
|
|
49
|
-
optional :per_page, :
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
optional :page, type: Integer, default: 1,
|
|
48
|
+
desc: "Page of results to fetch."
|
|
49
|
+
optional :per_page, type: Integer, default: options[:per_page],
|
|
50
|
+
desc: "Number of results to return per page.",
|
|
51
|
+
values: per_page_values
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
end
|
data/lib/rails/pagination.rb
CHANGED
|
@@ -3,7 +3,7 @@ module Rails
|
|
|
3
3
|
protected
|
|
4
4
|
|
|
5
5
|
def paginate(*options_or_collection)
|
|
6
|
-
options
|
|
6
|
+
options = options_or_collection.extract_options!
|
|
7
7
|
collection = options_or_collection.first
|
|
8
8
|
|
|
9
9
|
return _paginate_collection(collection, options) if collection
|
|
@@ -25,37 +25,35 @@ module Rails
|
|
|
25
25
|
private
|
|
26
26
|
|
|
27
27
|
def _discover_format(options)
|
|
28
|
-
|
|
29
|
-
return response_format if options.key?(response_format)
|
|
30
|
-
end
|
|
28
|
+
ApiPagination.config.response_formats.find { |format| options.key?(format) }
|
|
31
29
|
end
|
|
32
30
|
|
|
33
|
-
def _paginate_collection(collection, options={})
|
|
31
|
+
def _paginate_collection(collection, options = {})
|
|
34
32
|
options[:page] = ApiPagination.config.page_param(params)
|
|
35
33
|
options[:per_page] ||= ApiPagination.config.per_page_param(params)
|
|
36
34
|
|
|
37
35
|
collection, pagy = ApiPagination.paginate(collection, options)
|
|
38
36
|
|
|
39
|
-
links = (headers[
|
|
40
|
-
url
|
|
37
|
+
links = (headers["Link"] || "").split(",").map(&:strip)
|
|
38
|
+
url = base_url + request.path_info
|
|
41
39
|
pages = ApiPagination.pages_from(pagy || collection, options)
|
|
42
40
|
|
|
43
41
|
pages.each do |k, v|
|
|
44
|
-
new_params = request.query_parameters.merge(:
|
|
42
|
+
new_params = request.query_parameters.merge(page: v)
|
|
45
43
|
links << %(<#{url}?#{new_params.to_param}>; rel="#{k}")
|
|
46
44
|
end
|
|
47
45
|
|
|
48
|
-
total_header
|
|
46
|
+
total_header = ApiPagination.config.total_header
|
|
49
47
|
per_page_header = ApiPagination.config.per_page_header
|
|
50
|
-
page_header
|
|
51
|
-
include_total
|
|
48
|
+
page_header = ApiPagination.config.page_header
|
|
49
|
+
include_total = ApiPagination.config.include_total
|
|
52
50
|
|
|
53
|
-
headers[
|
|
51
|
+
headers["Link"] = links.join(", ") unless links.empty?
|
|
54
52
|
headers[per_page_header] = options[:per_page].to_s
|
|
55
53
|
headers[page_header] = options[:page].to_s unless page_header.nil?
|
|
56
54
|
headers[total_header] = total_count(pagy || collection, options).to_s if include_total
|
|
57
55
|
|
|
58
|
-
|
|
56
|
+
collection
|
|
59
57
|
end
|
|
60
58
|
|
|
61
59
|
def total_count(collection, options)
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: api-pagination
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 7.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David Celis
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: kaminari
|
|
@@ -36,20 +35,14 @@ dependencies:
|
|
|
36
35
|
requirements:
|
|
37
36
|
- - "~>"
|
|
38
37
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: '
|
|
40
|
-
- - ">="
|
|
41
|
-
- !ruby/object:Gem::Version
|
|
42
|
-
version: 5.1.2
|
|
38
|
+
version: '43.0'
|
|
43
39
|
type: :development
|
|
44
40
|
prerelease: false
|
|
45
41
|
version_requirements: !ruby/object:Gem::Requirement
|
|
46
42
|
requirements:
|
|
47
43
|
- - "~>"
|
|
48
44
|
- !ruby/object:Gem::Version
|
|
49
|
-
version: '
|
|
50
|
-
- - ">="
|
|
51
|
-
- !ruby/object:Gem::Version
|
|
52
|
-
version: 5.1.2
|
|
45
|
+
version: '43.0'
|
|
53
46
|
- !ruby/object:Gem::Dependency
|
|
54
47
|
name: will_paginate
|
|
55
48
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -104,40 +97,28 @@ dependencies:
|
|
|
104
97
|
requirements:
|
|
105
98
|
- - "~>"
|
|
106
99
|
- !ruby/object:Gem::Version
|
|
107
|
-
version: '
|
|
108
|
-
- - ">="
|
|
109
|
-
- !ruby/object:Gem::Version
|
|
110
|
-
version: 6.1.4.1
|
|
100
|
+
version: '7.0'
|
|
111
101
|
type: :development
|
|
112
102
|
prerelease: false
|
|
113
103
|
version_requirements: !ruby/object:Gem::Requirement
|
|
114
104
|
requirements:
|
|
115
105
|
- - "~>"
|
|
116
106
|
- !ruby/object:Gem::Version
|
|
117
|
-
version: '
|
|
118
|
-
- - ">="
|
|
119
|
-
- !ruby/object:Gem::Version
|
|
120
|
-
version: 6.1.4.1
|
|
107
|
+
version: '7.0'
|
|
121
108
|
- !ruby/object:Gem::Dependency
|
|
122
109
|
name: actionpack
|
|
123
110
|
requirement: !ruby/object:Gem::Requirement
|
|
124
111
|
requirements:
|
|
125
112
|
- - "~>"
|
|
126
113
|
- !ruby/object:Gem::Version
|
|
127
|
-
version: '
|
|
128
|
-
- - ">="
|
|
129
|
-
- !ruby/object:Gem::Version
|
|
130
|
-
version: 6.1.4.1
|
|
114
|
+
version: '7.0'
|
|
131
115
|
type: :development
|
|
132
116
|
prerelease: false
|
|
133
117
|
version_requirements: !ruby/object:Gem::Requirement
|
|
134
118
|
requirements:
|
|
135
119
|
- - "~>"
|
|
136
120
|
- !ruby/object:Gem::Version
|
|
137
|
-
version: '
|
|
138
|
-
- - ">="
|
|
139
|
-
- !ruby/object:Gem::Version
|
|
140
|
-
version: 6.1.4.1
|
|
121
|
+
version: '7.0'
|
|
141
122
|
- !ruby/object:Gem::Dependency
|
|
142
123
|
name: sequel
|
|
143
124
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -158,14 +139,14 @@ dependencies:
|
|
|
158
139
|
requirements:
|
|
159
140
|
- - "~>"
|
|
160
141
|
- !ruby/object:Gem::Version
|
|
161
|
-
version: 0.
|
|
142
|
+
version: 0.9.0
|
|
162
143
|
type: :development
|
|
163
144
|
prerelease: false
|
|
164
145
|
version_requirements: !ruby/object:Gem::Requirement
|
|
165
146
|
requirements:
|
|
166
147
|
- - "~>"
|
|
167
148
|
- !ruby/object:Gem::Version
|
|
168
|
-
version: 0.
|
|
149
|
+
version: 0.9.0
|
|
169
150
|
description: Link header pagination for Rails and Grape APIs
|
|
170
151
|
email:
|
|
171
152
|
- me@davidcel.is
|
|
@@ -180,25 +161,10 @@ files:
|
|
|
180
161
|
- lib/api-pagination/version.rb
|
|
181
162
|
- lib/grape/pagination.rb
|
|
182
163
|
- lib/rails/pagination.rb
|
|
183
|
-
- spec/active_record_spec.rb
|
|
184
|
-
- spec/api-pagination_spec.rb
|
|
185
|
-
- spec/grape_spec.rb
|
|
186
|
-
- spec/rails_spec.rb
|
|
187
|
-
- spec/sequel_spec.rb
|
|
188
|
-
- spec/spec_helper.rb
|
|
189
|
-
- spec/support/active_record/foo.rb
|
|
190
|
-
- spec/support/active_record/schema.rb
|
|
191
|
-
- spec/support/numbers_api.rb
|
|
192
|
-
- spec/support/numbers_controller.rb
|
|
193
|
-
- spec/support/shared_examples/existing_headers.rb
|
|
194
|
-
- spec/support/shared_examples/first_page.rb
|
|
195
|
-
- spec/support/shared_examples/last_page.rb
|
|
196
|
-
- spec/support/shared_examples/middle_page.rb
|
|
197
164
|
homepage: https://github.com/davidcelis/api-pagination
|
|
198
165
|
licenses:
|
|
199
166
|
- MIT
|
|
200
167
|
metadata: {}
|
|
201
|
-
post_install_message:
|
|
202
168
|
rdoc_options: []
|
|
203
169
|
require_paths:
|
|
204
170
|
- lib
|
|
@@ -213,22 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
213
179
|
- !ruby/object:Gem::Version
|
|
214
180
|
version: '0'
|
|
215
181
|
requirements: []
|
|
216
|
-
rubygems_version: 3.
|
|
217
|
-
signing_key:
|
|
182
|
+
rubygems_version: 3.6.9
|
|
218
183
|
specification_version: 4
|
|
219
184
|
summary: Link header pagination for Rails and Grape APIs. Don't use the request body.
|
|
220
|
-
test_files:
|
|
221
|
-
- spec/active_record_spec.rb
|
|
222
|
-
- spec/api-pagination_spec.rb
|
|
223
|
-
- spec/grape_spec.rb
|
|
224
|
-
- spec/rails_spec.rb
|
|
225
|
-
- spec/sequel_spec.rb
|
|
226
|
-
- spec/spec_helper.rb
|
|
227
|
-
- spec/support/active_record/foo.rb
|
|
228
|
-
- spec/support/active_record/schema.rb
|
|
229
|
-
- spec/support/numbers_api.rb
|
|
230
|
-
- spec/support/numbers_controller.rb
|
|
231
|
-
- spec/support/shared_examples/existing_headers.rb
|
|
232
|
-
- spec/support/shared_examples/first_page.rb
|
|
233
|
-
- spec/support/shared_examples/last_page.rb
|
|
234
|
-
- spec/support/shared_examples/middle_page.rb
|
|
185
|
+
test_files: []
|
data/spec/active_record_spec.rb
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'support/active_record/foo'
|
|
3
|
-
require 'nulldb_rspec'
|
|
4
|
-
|
|
5
|
-
ActiveRecord::Base.establish_connection(
|
|
6
|
-
adapter: :nulldb,
|
|
7
|
-
schema: 'spec/support/active_record/schema.rb'
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
NullDB.configure { |ndb| def ndb.project_root; Dir.pwd; end; }
|
|
11
|
-
|
|
12
|
-
shared_examples 'produces_correct_sql' do
|
|
13
|
-
it 'produces correct sql for first page' do
|
|
14
|
-
allow(collection).to receive(:count).and_return(collection_size)
|
|
15
|
-
paginated_sql, _ = ApiPagination.paginate(collection, per_page: per_page)
|
|
16
|
-
expect(paginated_sql.to_sql).to eql(Foo.limit(per_page).offset(0).to_sql)
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
describe 'ActiveRecord Support' do
|
|
21
|
-
let(:collection) { Foo.all }
|
|
22
|
-
let(:collection_size) { 50 }
|
|
23
|
-
let(:per_page) { 5 }
|
|
24
|
-
|
|
25
|
-
if ApiPagination.config.paginator == :will_paginate
|
|
26
|
-
require 'will_paginate/active_record'
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
context "pagination with #{ApiPagination.config.paginator}" do
|
|
30
|
-
include_examples 'produces_correct_sql'
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if ApiPagination.config.paginator != :pagy
|
|
35
|
-
context 'reflections' do
|
|
36
|
-
it 'invokes the correct methods to determine type' do
|
|
37
|
-
expect(collection).to receive(:klass).at_least(:once)
|
|
38
|
-
.and_call_original
|
|
39
|
-
ApiPagination.paginate(collection)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it 'does not fail if table name is not snake cased class name' do
|
|
43
|
-
allow(collection).to receive(:table_name).and_return(SecureRandom.uuid)
|
|
44
|
-
expect { ApiPagination.paginate(collection) }.to_not raise_error
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
|