Skip to content

Commit a517c4b

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 a517c4b

File tree

10 files changed

+304
-2
lines changed

10 files changed

+304
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
.bundle
44
.config
55
.yardoc
6+
.ruby-version
67
Gemfile.lock
78
InstalledFiles
89
_yardoc

.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+

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 'appraisal'
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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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 "sqlite3", :require => false
8+
gem "sequel", :require => false
9+
gem "grape", "~> 0.10.1"
10+
11+
gemspec :path => "../"

gemfiles/grape_0.10.gemfile.lock

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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+
descendants_tracker (0.0.4)
40+
thread_safe (~> 0.3, >= 0.3.1)
41+
diff-lcs (1.2.5)
42+
equalizer (0.0.9)
43+
erubis (2.7.0)
44+
grape (0.10.1)
45+
activesupport
46+
builder
47+
hashie (>= 2.1.0)
48+
multi_json (>= 1.3.2)
49+
multi_xml (>= 0.5.2)
50+
rack (>= 1.3.0)
51+
rack-accept
52+
rack-mount
53+
virtus (>= 1.0.0)
54+
hashie (3.3.2)
55+
i18n (0.7.0)
56+
ice_nine (0.11.1)
57+
json (1.8.2)
58+
kaminari (0.16.1)
59+
actionpack (>= 3.0.0)
60+
activesupport (>= 3.0.0)
61+
loofah (2.0.1)
62+
nokogiri (>= 1.5.9)
63+
mini_portile (0.6.2)
64+
minitest (5.5.0)
65+
multi_json (1.10.1)
66+
multi_xml (0.5.5)
67+
nokogiri (1.6.5)
68+
mini_portile (~> 0.6.0)
69+
rack (1.6.0)
70+
rack-accept (0.4.5)
71+
rack (>= 0.4)
72+
rack-mount (0.8.3)
73+
rack (>= 1.0.0)
74+
rack-test (0.6.3)
75+
rack (>= 1.0)
76+
rails-deprecated_sanitizer (1.0.3)
77+
activesupport (>= 4.2.0.alpha)
78+
rails-dom-testing (1.0.5)
79+
activesupport (>= 4.2.0.beta, < 5.0)
80+
nokogiri (~> 1.6.0)
81+
rails-deprecated_sanitizer (>= 1.0.1)
82+
rails-html-sanitizer (1.0.1)
83+
loofah (~> 2.0)
84+
railties (4.2.0)
85+
actionpack (= 4.2.0)
86+
activesupport (= 4.2.0)
87+
rake (>= 0.8.7)
88+
thor (>= 0.18.1, < 2.0)
89+
rake (10.4.2)
90+
rspec (3.1.0)
91+
rspec-core (~> 3.1.0)
92+
rspec-expectations (~> 3.1.0)
93+
rspec-mocks (~> 3.1.0)
94+
rspec-core (3.1.7)
95+
rspec-support (~> 3.1.0)
96+
rspec-expectations (3.1.2)
97+
diff-lcs (>= 1.2.0, < 2.0)
98+
rspec-support (~> 3.1.0)
99+
rspec-mocks (3.1.3)
100+
rspec-support (~> 3.1.0)
101+
rspec-support (3.1.2)
102+
sequel (4.18.0)
103+
sqlite3 (1.3.10)
104+
thor (0.19.1)
105+
thread_safe (0.3.4)
106+
tzinfo (1.2.2)
107+
thread_safe (~> 0.1)
108+
virtus (1.0.4)
109+
axiom-types (~> 0.1)
110+
coercible (~> 1.0)
111+
descendants_tracker (~> 0.0, >= 0.0.3)
112+
equalizer (~> 0.0, >= 0.0.9)
113+
will_paginate (3.0.7)
114+
115+
PLATFORMS
116+
ruby
117+
118+
DEPENDENCIES
119+
actionpack (>= 3.0.0)
120+
api-pagination!
121+
appraisal
122+
grape (~> 0.10.1)
123+
kaminari
124+
railties (>= 3.0.0)
125+
rspec (~> 3.0)
126+
sequel
127+
sqlite3
128+
will_paginate

gemfiles/grape_0.9.gemfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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 "sqlite3", :require => false
8+
gem "sequel", :require => false
9+
gem "grape", "~> 0.9.0"
10+
11+
gemspec :path => "../"

gemfiles/grape_0.9.gemfile.lock

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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+
descendants_tracker (0.0.4)
40+
thread_safe (~> 0.3, >= 0.3.1)
41+
diff-lcs (1.2.5)
42+
equalizer (0.0.9)
43+
erubis (2.7.0)
44+
grape (0.9.0)
45+
activesupport
46+
builder
47+
hashie (>= 2.1.0)
48+
multi_json (>= 1.3.2)
49+
multi_xml (>= 0.5.2)
50+
rack (>= 1.3.0)
51+
rack-accept
52+
rack-mount
53+
virtus (>= 1.0.0)
54+
hashie (3.3.2)
55+
i18n (0.7.0)
56+
ice_nine (0.11.1)
57+
json (1.8.2)
58+
kaminari (0.16.1)
59+
actionpack (>= 3.0.0)
60+
activesupport (>= 3.0.0)
61+
loofah (2.0.1)
62+
nokogiri (>= 1.5.9)
63+
mini_portile (0.6.2)
64+
minitest (5.5.0)
65+
multi_json (1.10.1)
66+
multi_xml (0.5.5)
67+
nokogiri (1.6.5)
68+
mini_portile (~> 0.6.0)
69+
rack (1.6.0)
70+
rack-accept (0.4.5)
71+
rack (>= 0.4)
72+
rack-mount (0.8.3)
73+
rack (>= 1.0.0)
74+
rack-test (0.6.3)
75+
rack (>= 1.0)
76+
rails-deprecated_sanitizer (1.0.3)
77+
activesupport (>= 4.2.0.alpha)
78+
rails-dom-testing (1.0.5)
79+
activesupport (>= 4.2.0.beta, < 5.0)
80+
nokogiri (~> 1.6.0)
81+
rails-deprecated_sanitizer (>= 1.0.1)
82+
rails-html-sanitizer (1.0.1)
83+
loofah (~> 2.0)
84+
railties (4.2.0)
85+
actionpack (= 4.2.0)
86+
activesupport (= 4.2.0)
87+
rake (>= 0.8.7)
88+
thor (>= 0.18.1, < 2.0)
89+
rake (10.4.2)
90+
rspec (3.1.0)
91+
rspec-core (~> 3.1.0)
92+
rspec-expectations (~> 3.1.0)
93+
rspec-mocks (~> 3.1.0)
94+
rspec-core (3.1.7)
95+
rspec-support (~> 3.1.0)
96+
rspec-expectations (3.1.2)
97+
diff-lcs (>= 1.2.0, < 2.0)
98+
rspec-support (~> 3.1.0)
99+
rspec-mocks (3.1.3)
100+
rspec-support (~> 3.1.0)
101+
rspec-support (3.1.2)
102+
sequel (4.18.0)
103+
sqlite3 (1.3.10)
104+
thor (0.19.1)
105+
thread_safe (0.3.4)
106+
tzinfo (1.2.2)
107+
thread_safe (~> 0.1)
108+
virtus (1.0.4)
109+
axiom-types (~> 0.1)
110+
coercible (~> 1.0)
111+
descendants_tracker (~> 0.0, >= 0.0.3)
112+
equalizer (~> 0.0, >= 0.0.9)
113+
will_paginate (3.0.7)
114+
115+
PLATFORMS
116+
ruby
117+
118+
DEPENDENCIES
119+
actionpack (>= 3.0.0)
120+
api-pagination!
121+
appraisal
122+
grape (~> 0.9.0)
123+
kaminari
124+
railties (>= 3.0.0)
125+
rspec (~> 3.0)
126+
sequel
127+
sqlite3
128+
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

0 commit comments

Comments
 (0)