api-pagination 3.0.2 → 3.1.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.rb +1 -1
- data/lib/api-pagination/version.rb +2 -2
- data/lib/rails/pagination.rb +7 -2
- data/spec/rails_spec.rb +10 -0
- data/spec/sequel_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -3
- data/spec/support/numbers_controller.rb +21 -2
- metadata +6 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c576834fa7e045c8227f8ac9eb178dedc241533
|
4
|
+
data.tar.gz: 6c620fe958d4b4c87e8df6d28faf4a24c500e2e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b22e56913a84c875f177f1e3acb401bcb4decf175ed31023efe6cfdc33782d7d67e1b84e85cf8f0a9454181aa2284047d24c0f8c43b9b7328266c8e28500beaf
|
7
|
+
data.tar.gz: c23680b6346a5dab04bbecfd6a18ec4d54190f2907b488936743108eaf4657b66d02724ab64feab558f731ca80e1287784c3fa2c7e7634df163e44b167a3c38a
|
data/lib/api-pagination.rb
CHANGED
data/lib/rails/pagination.rb
CHANGED
@@ -2,10 +2,15 @@ module Rails
|
|
2
2
|
module Pagination
|
3
3
|
protected
|
4
4
|
|
5
|
-
def paginate(
|
5
|
+
def paginate(*options_or_collection)
|
6
|
+
options = options_or_collection.extract_options!
|
7
|
+
collection = options_or_collection.first
|
8
|
+
|
9
|
+
return _paginate_collection(collection, options) if collection
|
10
|
+
|
6
11
|
collection = options[:json] || options[:xml]
|
12
|
+
collection = _paginate_collection(collection, options)
|
7
13
|
|
8
|
-
collection = _paginate_collection(collection, options)
|
9
14
|
options[:json] = collection if options[:json]
|
10
15
|
options[:xml] = collection if options[:xml]
|
11
16
|
|
data/spec/rails_spec.rb
CHANGED
@@ -53,6 +53,16 @@ describe NumbersController, :type => :controller do
|
|
53
53
|
it_behaves_like 'an endpoint with a middle page'
|
54
54
|
end
|
55
55
|
end
|
56
|
+
|
57
|
+
context 'providing a block' do
|
58
|
+
it 'yields to the block instead of implicitly rendering' do
|
59
|
+
get :index_with_custom_render, :count => 100
|
60
|
+
|
61
|
+
json = { numbers: (1..10).map { |n| { number: n } } }.to_json
|
62
|
+
|
63
|
+
expect(response.body).to eq(json)
|
64
|
+
end
|
65
|
+
end
|
56
66
|
end
|
57
67
|
end
|
58
68
|
|
data/spec/sequel_spec.rb
CHANGED
@@ -24,7 +24,7 @@ if ApiPagination.paginator == :will_paginate
|
|
24
24
|
|
25
25
|
it 'returns a Sequel::Dataset' do
|
26
26
|
collection = ApiPagination.paginate(people)
|
27
|
-
expect(collection.kind_of?(Sequel::Dataset)).to
|
27
|
+
expect(collection.kind_of?(Sequel::Dataset)).to be_truthy
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -39,14 +39,25 @@ module ControllerExampleGroup
|
|
39
39
|
end
|
40
40
|
|
41
41
|
Rails.application.routes.draw do
|
42
|
-
resources :numbers, :only => [:index]
|
42
|
+
resources :numbers, :only => [:index] do
|
43
|
+
get :index_with_custom_render, on: :collection
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class NumbersSerializer
|
48
|
+
def initialize(numbers)
|
49
|
+
@numbers = numbers
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_json(options = {})
|
53
|
+
{ numbers: @numbers.map { |n| { number: n } } }.to_json
|
54
|
+
end
|
43
55
|
end
|
44
56
|
|
45
57
|
class NumbersController < ActionController::Base
|
46
58
|
include Rails.application.routes.url_helpers
|
47
59
|
|
48
60
|
def index
|
49
|
-
page = params.fetch(:page, 1).to_i
|
50
61
|
total = params.fetch(:count).to_i
|
51
62
|
|
52
63
|
if params[:with_headers]
|
@@ -57,4 +68,12 @@ class NumbersController < ActionController::Base
|
|
57
68
|
|
58
69
|
paginate :json => (1..total).to_a, :per_page => 10
|
59
70
|
end
|
71
|
+
|
72
|
+
def index_with_custom_render
|
73
|
+
total = params.fetch(:count).to_i
|
74
|
+
numbers = (1..total).to_a
|
75
|
+
numbers = paginate numbers, :per_page => 10
|
76
|
+
|
77
|
+
render json: NumbersSerializer.new(numbers)
|
78
|
+
end
|
60
79
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api-pagination
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Celis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '3.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: grape
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,20 +66,6 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 3.0.0
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: sqlite3
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: sequel
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -151,4 +137,3 @@ test_files:
|
|
151
137
|
- spec/support/shared_examples/first_page.rb
|
152
138
|
- spec/support/shared_examples/last_page.rb
|
153
139
|
- spec/support/shared_examples/middle_page.rb
|
154
|
-
has_rdoc:
|