Skip to content

Commit 6391102

Browse files
author
Mason McLead
committed
support for Grape 0.10 with refactored settings and maintaining support for Grape 0.9
1 parent 2a546ed commit 6391102

13 files changed

+326
-2
lines changed

.ruby

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.1.0

.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.1.0

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ script: bundle exec rspec
77
env:
88
- PAGINATOR=kaminari
99
- PAGINATOR=will_paginate
10+
gemfile:
11+
- gemfiles/grape_0.10.gemfile
12+
- gemfiles/grape_0.9.gemfile

Appraisals

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
appraise "grape-0.10" do
2+
gem "grape", "~> 0.10.1"
3+
end
4+
appraise "grape-0.9" do
5+
gem "grape", "~> 0.9.0"
6+
end
7+

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ gemspec
66
gem 'kaminari', require: false
77
gem 'will_paginate', require: false
88

9+
gem 'appraisal'
10+
911
gem 'sqlite3', require: false
1012
gem 'sequel', require: false

Rakefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
2+
task :default => :appraisal
3+
end

api-pagination.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
1818

1919
s.add_development_dependency 'rspec', '~> 3.0'
2020
s.add_development_dependency 'grape'
21+
s.add_development_dependency 'debugger'
2122
s.add_development_dependency 'railties', '>= 3.0.0'
2223
s.add_development_dependency 'actionpack', '>= 3.0.0'
2324
s.add_development_dependency 'sequel', '>= 4.9.0'

gemfiles/grape_0.10.gemfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file was generated by Appraisal
2+
3+
source "https://rubygems.org"
4+
5+
gem "kaminari", :require => false
6+
gem "will_paginate", :require => false
7+
gem "appraisal"
8+
gem "sqlite3", :require => false
9+
gem "sequel", :require => false
10+
gem "grape", "~> 0.10.1"
11+
12+
gemspec :path => "../"

gemfiles/grape_0.10.gemfile.lock

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
PATH
2+
remote: ../
3+
specs:
4+
api-pagination (3.1.0)
5+
6+
GEM
7+
remote: https://rubygems.org/
8+
specs:
9+
actionpack (4.2.0)
10+
actionview (= 4.2.0)
11+
activesupport (= 4.2.0)
12+
rack (~> 1.6.0)
13+
rack-test (~> 0.6.2)
14+
rails-dom-testing (~> 1.0, >= 1.0.5)
15+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
16+
actionview (4.2.0)
17+
activesupport (= 4.2.0)
18+
builder (~> 3.1)
19+
erubis (~> 2.7.0)
20+
rails-dom-testing (~> 1.0, >= 1.0.5)
21+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
22+
activesupport (4.2.0)
23+
i18n (~> 0.7)
24+
json (~> 1.7, >= 1.7.7)
25+
minitest (~> 5.1)
26+
thread_safe (~> 0.3, >= 0.3.4)
27+
tzinfo (~> 1.1)
28+
appraisal (1.0.2)
29+
bundler
30+
rake
31+
thor (>= 0.14.0)
32+
axiom-types (0.1.1)
33+
descendants_tracker (~> 0.0.4)
34+
ice_nine (~> 0.11.0)
35+
thread_safe (~> 0.3, >= 0.3.1)
36+
builder (3.2.2)
37+
coercible (1.0.0)
38+
descendants_tracker (~> 0.0.1)
39+
columnize (0.9.0)
40+
debugger (1.6.8)
41+
columnize (>= 0.3.1)
42+
debugger-linecache (~> 1.2.0)
43+
debugger-ruby_core_source (~> 1.3.5)
44+
debugger-linecache (1.2.0)
45+
debugger-ruby_core_source (1.3.7)
46+
descendants_tracker (0.0.4)
47+
thread_safe (~> 0.3, >= 0.3.1)
48+
diff-lcs (1.2.5)
49+
equalizer (0.0.9)
50+
erubis (2.7.0)
51+
grape (0.10.1)
52+
activesupport
53+
builder
54+
hashie (>= 2.1.0)
55+
multi_json (>= 1.3.2)
56+
multi_xml (>= 0.5.2)
57+
rack (>= 1.3.0)
58+
rack-accept
59+
rack-mount
60+
virtus (>= 1.0.0)
61+
hashie (3.3.2)
62+
i18n (0.7.0)
63+
ice_nine (0.11.1)
64+
json (1.8.2)
65+
kaminari (0.16.1)
66+
actionpack (>= 3.0.0)
67+
activesupport (>= 3.0.0)
68+
loofah (2.0.1)
69+
nokogiri (>= 1.5.9)
70+
mini_portile (0.6.2)
71+
minitest (5.5.0)
72+
multi_json (1.10.1)
73+
multi_xml (0.5.5)
74+
nokogiri (1.6.5)
75+
mini_portile (~> 0.6.0)
76+
rack (1.6.0)
77+
rack-accept (0.4.5)
78+
rack (>= 0.4)
79+
rack-mount (0.8.3)
80+
rack (>= 1.0.0)
81+
rack-test (0.6.3)
82+
rack (>= 1.0)
83+
rails-deprecated_sanitizer (1.0.3)
84+
activesupport (>= 4.2.0.alpha)
85+
rails-dom-testing (1.0.5)
86+
activesupport (>= 4.2.0.beta, < 5.0)
87+
nokogiri (~> 1.6.0)
88+
rails-deprecated_sanitizer (>= 1.0.1)
89+
rails-html-sanitizer (1.0.1)
90+
loofah (~> 2.0)
91+
railties (4.2.0)
92+
actionpack (= 4.2.0)
93+
activesupport (= 4.2.0)
94+
rake (>= 0.8.7)
95+
thor (>= 0.18.1, < 2.0)
96+
rake (10.4.2)
97+
rspec (3.1.0)
98+
rspec-core (~> 3.1.0)
99+
rspec-expectations (~> 3.1.0)
100+
rspec-mocks (~> 3.1.0)
101+
rspec-core (3.1.7)
102+
rspec-support (~> 3.1.0)
103+
rspec-expectations (3.1.2)
104+
diff-lcs (>= 1.2.0, < 2.0)
105+
rspec-support (~> 3.1.0)
106+
rspec-mocks (3.1.3)
107+
rspec-support (~> 3.1.0)
108+
rspec-support (3.1.2)
109+
sequel (4.18.0)
110+
sqlite3 (1.3.10)
111+
thor (0.19.1)
112+
thread_safe (0.3.4)
113+
tzinfo (1.2.2)
114+
thread_safe (~> 0.1)
115+
virtus (1.0.4)
116+
axiom-types (~> 0.1)
117+
coercible (~> 1.0)
118+
descendants_tracker (~> 0.0, >= 0.0.3)
119+
equalizer (~> 0.0, >= 0.0.9)
120+
will_paginate (3.0.7)
121+
122+
PLATFORMS
123+
ruby
124+
125+
DEPENDENCIES
126+
actionpack (>= 3.0.0)
127+
api-pagination!
128+
appraisal
129+
debugger
130+
grape (~> 0.10.1)
131+
kaminari
132+
railties (>= 3.0.0)
133+
rspec (~> 3.0)
134+
sequel
135+
sqlite3
136+
will_paginate

gemfiles/grape_0.9.gemfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file was generated by Appraisal
2+
3+
source "https://rubygems.org"
4+
5+
gem "kaminari", :require => false
6+
gem "will_paginate", :require => false
7+
gem "appraisal"
8+
gem "sqlite3", :require => false
9+
gem "sequel", :require => false
10+
gem "grape", "~> 0.9.0"
11+
12+
gemspec :path => "../"

gemfiles/grape_0.9.gemfile.lock

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
PATH
2+
remote: ../
3+
specs:
4+
api-pagination (3.1.0)
5+
6+
GEM
7+
remote: https://rubygems.org/
8+
specs:
9+
actionpack (4.2.0)
10+
actionview (= 4.2.0)
11+
activesupport (= 4.2.0)
12+
rack (~> 1.6.0)
13+
rack-test (~> 0.6.2)
14+
rails-dom-testing (~> 1.0, >= 1.0.5)
15+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
16+
actionview (4.2.0)
17+
activesupport (= 4.2.0)
18+
builder (~> 3.1)
19+
erubis (~> 2.7.0)
20+
rails-dom-testing (~> 1.0, >= 1.0.5)
21+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
22+
activesupport (4.2.0)
23+
i18n (~> 0.7)
24+
json (~> 1.7, >= 1.7.7)
25+
minitest (~> 5.1)
26+
thread_safe (~> 0.3, >= 0.3.4)
27+
tzinfo (~> 1.1)
28+
appraisal (1.0.2)
29+
bundler
30+
rake
31+
thor (>= 0.14.0)
32+
axiom-types (0.1.1)
33+
descendants_tracker (~> 0.0.4)
34+
ice_nine (~> 0.11.0)
35+
thread_safe (~> 0.3, >= 0.3.1)
36+
builder (3.2.2)
37+
coercible (1.0.0)
38+
descendants_tracker (~> 0.0.1)
39+
columnize (0.9.0)
40+
debugger (1.6.8)
41+
columnize (>= 0.3.1)
42+
debugger-linecache (~> 1.2.0)
43+
debugger-ruby_core_source (~> 1.3.5)
44+
debugger-linecache (1.2.0)
45+
debugger-ruby_core_source (1.3.7)
46+
descendants_tracker (0.0.4)
47+
thread_safe (~> 0.3, >= 0.3.1)
48+
diff-lcs (1.2.5)
49+
equalizer (0.0.9)
50+
erubis (2.7.0)
51+
grape (0.9.0)
52+
activesupport
53+
builder
54+
hashie (>= 2.1.0)
55+
multi_json (>= 1.3.2)
56+
multi_xml (>= 0.5.2)
57+
rack (>= 1.3.0)
58+
rack-accept
59+
rack-mount
60+
virtus (>= 1.0.0)
61+
hashie (3.3.2)
62+
i18n (0.7.0)
63+
ice_nine (0.11.1)
64+
json (1.8.2)
65+
kaminari (0.16.1)
66+
actionpack (>= 3.0.0)
67+
activesupport (>= 3.0.0)
68+
loofah (2.0.1)
69+
nokogiri (>= 1.5.9)
70+
mini_portile (0.6.2)
71+
minitest (5.5.0)
72+
multi_json (1.10.1)
73+
multi_xml (0.5.5)
74+
nokogiri (1.6.5)
75+
mini_portile (~> 0.6.0)
76+
rack (1.6.0)
77+
rack-accept (0.4.5)
78+
rack (>= 0.4)
79+
rack-mount (0.8.3)
80+
rack (>= 1.0.0)
81+
rack-test (0.6.3)
82+
rack (>= 1.0)
83+
rails-deprecated_sanitizer (1.0.3)
84+
activesupport (>= 4.2.0.alpha)
85+
rails-dom-testing (1.0.5)
86+
activesupport (>= 4.2.0.beta, < 5.0)
87+
nokogiri (~> 1.6.0)
88+
rails-deprecated_sanitizer (>= 1.0.1)
89+
rails-html-sanitizer (1.0.1)
90+
loofah (~> 2.0)
91+
railties (4.2.0)
92+
actionpack (= 4.2.0)
93+
activesupport (= 4.2.0)
94+
rake (>= 0.8.7)
95+
thor (>= 0.18.1, < 2.0)
96+
rake (10.4.2)
97+
rspec (3.1.0)
98+
rspec-core (~> 3.1.0)
99+
rspec-expectations (~> 3.1.0)
100+
rspec-mocks (~> 3.1.0)
101+
rspec-core (3.1.7)
102+
rspec-support (~> 3.1.0)
103+
rspec-expectations (3.1.2)
104+
diff-lcs (>= 1.2.0, < 2.0)
105+
rspec-support (~> 3.1.0)
106+
rspec-mocks (3.1.3)
107+
rspec-support (~> 3.1.0)
108+
rspec-support (3.1.2)
109+
sequel (4.18.0)
110+
sqlite3 (1.3.10)
111+
thor (0.19.1)
112+
thread_safe (0.3.4)
113+
tzinfo (1.2.2)
114+
thread_safe (~> 0.1)
115+
virtus (1.0.4)
116+
axiom-types (~> 0.1)
117+
coercible (~> 1.0)
118+
descendants_tracker (~> 0.0, >= 0.0.3)
119+
equalizer (~> 0.0, >= 0.0.9)
120+
will_paginate (3.0.7)
121+
122+
PLATFORMS
123+
ruby
124+
125+
DEPENDENCIES
126+
actionpack (>= 3.0.0)
127+
api-pagination!
128+
appraisal
129+
debugger
130+
grape (~> 0.9.0)
131+
kaminari
132+
railties (>= 3.0.0)
133+
rspec (~> 3.0)
134+
sequel
135+
sqlite3
136+
will_paginate

lib/grape/pagination.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def self.included(base)
55
def paginate(collection)
66
options = {
77
:page => params[:page],
8-
:per_page => (params[:per_page] || settings[:per_page])
8+
:per_page => (params[:per_page] || Grape::Pagination.grape_settings(self, :per_page))
99
}
1010
collection = ApiPagination.paginate(collection, options)
1111

@@ -28,7 +28,7 @@ def paginate(collection)
2828

2929
base.class_eval do
3030
def self.paginate(options = {})
31-
set :per_page, (options[:per_page] || 25)
31+
Grape::Pagination.set_grape_settings(self, :per_page, (options[:per_page] || 25))
3232
params do
3333
optional :page, :type => Integer, :default => 1,
3434
:desc => 'Page of results to fetch.'
@@ -37,6 +37,15 @@ def self.paginate(options = {})
3737
end
3838
end
3939
end
40+
41+
#support grape 0.9 and 0.10
42+
def self.grape_settings(endpoint, setting)
43+
endpoint.respond_to?(:settings) ? endpoint.settings[setting] : endpoint.namespace_inheritable(setting)
44+
end
45+
46+
def self.set_grape_settings(endpoint, *args)
47+
endpoint.respond_to?(:set) ? endpoint.set(*args) : endpoint.namespace_inheritable(*args)
48+
end
4049
end
4150
end
4251
end

spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
ApiPagination.instance_variable_set(:@paginator, :kaminari)
66
end
77

8+
require 'debugger'
89
require 'support/numbers_controller'
910
require 'support/numbers_api'
1011
require 'api-pagination'

0 commit comments

Comments
 (0)