standardapi 5.2.0.5 → 5.2.0.6
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
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4b7a8c23e3996a005396e58c1586e921276a66d9c7bb69a2c3679d72eb4e56a
|
4
|
+
data.tar.gz: 840ae632d429e954b66edbba5f4cba69c5c0ab17ec6bda8b2e18e34c10040880
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c395e361f79fce96f322ab5311a812300c416b05a28e46ae070164da15f8df23a2754663843ecf7969b736f0d7188142586d8c7b18a1d3d5d300a255cefc63bb
|
7
|
+
data.tar.gz: 863685a1c335afc5315545f0c511472a58cc588eccbe2a3273cac6a43d11cb86118eab40bdf6043ab3165a107fbddcca7381114dbdf3cb38fb6ed41ea51fd6b3
|
@@ -2,7 +2,7 @@ module StandardAPI
|
|
2
2
|
module Controller
|
3
3
|
|
4
4
|
def self.included(klass)
|
5
|
-
klass.helper_method :includes, :orders, :model, :resource_limit
|
5
|
+
klass.helper_method :includes, :orders, :model, :resource_limit, :default_limit
|
6
6
|
klass.before_action :set_standardapi_headers
|
7
7
|
klass.append_view_path(File.join(File.dirname(__FILE__), 'views'))
|
8
8
|
klass.extend(ClassMethods)
|
@@ -208,11 +208,20 @@ module StandardAPI
|
|
208
208
|
1000
|
209
209
|
end
|
210
210
|
|
211
|
+
# The default limit if params[:limit] is no specified in a request.
|
212
|
+
# If this value should be less than the `resource_limit`. Return `nil` if
|
213
|
+
# you want the limit param to be required.
|
214
|
+
def default_limit
|
215
|
+
nil
|
216
|
+
end
|
217
|
+
|
211
218
|
def limit
|
212
219
|
if resource_limit
|
213
|
-
limit = params.
|
220
|
+
limit = params.permit(:limit)[:limit]&.to_i || default_limit
|
214
221
|
|
215
|
-
if limit
|
222
|
+
if !limit
|
223
|
+
raise ActionController::ParameterMissing.new(:limit)
|
224
|
+
elsif limit > resource_limit
|
216
225
|
raise ActionController::UnpermittedParameters.new([:limit, limit])
|
217
226
|
end
|
218
227
|
|
@@ -13,6 +13,7 @@ module StandardAPI
|
|
13
13
|
|
14
14
|
test '#index.json requires limit' do
|
15
15
|
return if !resource_limit || resource_limit == Float::INFINITY
|
16
|
+
return if default_limit
|
16
17
|
|
17
18
|
begin
|
18
19
|
get resource_path(:index, format: :json)
|
@@ -21,6 +22,13 @@ module StandardAPI
|
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
25
|
+
test '#index.json uses default_limit' do
|
26
|
+
return if !default_limit
|
27
|
+
|
28
|
+
get resource_path(:index, format: :json)
|
29
|
+
assert_response :ok
|
30
|
+
end
|
31
|
+
|
24
32
|
test '#index.json params[:limit]' do
|
25
33
|
get resource_path(:index, format: :json), params: { limit: 1 }
|
26
34
|
models = @controller.instance_variable_get("@#{plural_name}")
|
data/lib/standard_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: standardapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.2.0.
|
4
|
+
version: 5.2.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Bracy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -324,7 +324,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
324
324
|
version: '0'
|
325
325
|
requirements: []
|
326
326
|
rubyforge_project:
|
327
|
-
rubygems_version: 2.7.
|
327
|
+
rubygems_version: 2.7.7
|
328
328
|
signing_key:
|
329
329
|
specification_version: 4
|
330
330
|
summary: StandardAPI makes it easy to expose a query interface for your Rails models
|