rest_framework 0.6.7 → 0.6.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rest_framework/controller_mixins/base.rb +41 -12
- data/lib/rest_framework/controller_mixins/models.rb +16 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b74a4553ac1297795e4bb614e395e6b21a8c3ba18ef11ca36594e76bc51c3aac
|
4
|
+
data.tar.gz: 948044b9b604fe754aad64db509351478d869b298a87d382e19dd3a95eba7087
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42780202ca53a1e52a6c866e01c0ae428c2f54bafe3c4f2e0f7be599139f3159cade939346f8018ddc4e3b2a4ad37dbbedef5377c97e1df1e84c2f09dbd6a31d
|
7
|
+
data.tar.gz: 6e50a220a25ed28f1f1b0d71fdaf73a1f8fe6caf5c3130779621cb4528a5774008e6c379ad0a98c12132740d962f3dac786f0a17e9691c6b5a7e09586f96bf6e
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.9
|
@@ -36,23 +36,28 @@ module RESTFramework::BaseControllerMixin
|
|
36
36
|
{
|
37
37
|
filter_pk_from_request_body: true,
|
38
38
|
exclude_body_fields: [:created_at, :created_by, :updated_at, :updated_by],
|
39
|
-
accept_generic_params_as_body_params:
|
39
|
+
accept_generic_params_as_body_params: false,
|
40
|
+
show_backtrace: false,
|
40
41
|
extra_actions: nil,
|
41
42
|
extra_member_actions: nil,
|
42
43
|
filter_backends: nil,
|
44
|
+
singleton_controller: nil,
|
45
|
+
skip_actions: nil,
|
46
|
+
|
47
|
+
# Options related to serialization.
|
48
|
+
rescue_unknown_format_with: :json,
|
49
|
+
serializer_class: nil,
|
50
|
+
serialize_to_json: true,
|
51
|
+
serialize_to_xml: true,
|
52
|
+
|
53
|
+
# Options related to pagination.
|
43
54
|
paginator_class: nil,
|
44
55
|
page_size: 20,
|
45
56
|
page_query_param: "page",
|
46
57
|
page_size_query_param: "page_size",
|
47
58
|
max_page_size: nil,
|
48
|
-
rescue_unknown_format_with: :json,
|
49
|
-
serializer_class: nil,
|
50
|
-
serialize_to_json: true,
|
51
|
-
serialize_to_xml: true,
|
52
|
-
singleton_controller: nil,
|
53
|
-
skip_actions: nil,
|
54
59
|
|
55
|
-
#
|
60
|
+
# Option to disable serializer adapters by default, mainly introduced because Active Model
|
56
61
|
# Serializers will do things like serialize `[]` into `{"":[]}`.
|
57
62
|
disable_adapters_by_default: true,
|
58
63
|
}.each do |a, default|
|
@@ -83,6 +88,7 @@ module RESTFramework::BaseControllerMixin
|
|
83
88
|
base.rescue_from(ActiveRecord::RecordInvalid, with: :record_invalid)
|
84
89
|
base.rescue_from(ActiveRecord::RecordNotSaved, with: :record_not_saved)
|
85
90
|
base.rescue_from(ActiveRecord::RecordNotDestroyed, with: :record_not_destroyed)
|
91
|
+
base.rescue_from(ActiveModel::UnknownAttributeError, with: :unknown_attribute_error)
|
86
92
|
end
|
87
93
|
end
|
88
94
|
|
@@ -126,23 +132,46 @@ module RESTFramework::BaseControllerMixin
|
|
126
132
|
|
127
133
|
def record_invalid(e)
|
128
134
|
return api_response(
|
129
|
-
{
|
135
|
+
{
|
136
|
+
message: "Record invalid.", errors: e.record&.errors
|
137
|
+
}.merge(self.class.show_backtrace ? {exception: e.full_message} : {}),
|
138
|
+
status: 400,
|
130
139
|
)
|
131
140
|
end
|
132
141
|
|
133
142
|
def record_not_found(e)
|
134
|
-
return api_response(
|
143
|
+
return api_response(
|
144
|
+
{
|
145
|
+
message: "Record not found.",
|
146
|
+
}.merge(self.class.show_backtrace ? {exception: e.full_message} : {}),
|
147
|
+
status: 404,
|
148
|
+
)
|
135
149
|
end
|
136
150
|
|
137
151
|
def record_not_saved(e)
|
138
152
|
return api_response(
|
139
|
-
{
|
153
|
+
{
|
154
|
+
message: "Record not saved.", errors: e.record&.errors
|
155
|
+
}.merge(self.class.show_backtrace ? {exception: e.full_message} : {}),
|
156
|
+
status: 400,
|
140
157
|
)
|
141
158
|
end
|
142
159
|
|
143
160
|
def record_not_destroyed(e)
|
144
161
|
return api_response(
|
145
|
-
{
|
162
|
+
{
|
163
|
+
message: "Record not destroyed.", errors: e.record&.errors
|
164
|
+
}.merge(self.class.show_backtrace ? {exception: e.full_message} : {}),
|
165
|
+
status: 400,
|
166
|
+
)
|
167
|
+
end
|
168
|
+
|
169
|
+
def unknown_attribute_error(e)
|
170
|
+
return api_response(
|
171
|
+
{
|
172
|
+
message: e.message.capitalize,
|
173
|
+
}.merge(self.class.show_backtrace ? {exception: e.full_message} : {}),
|
174
|
+
status: 400,
|
146
175
|
)
|
147
176
|
end
|
148
177
|
|
@@ -125,17 +125,17 @@ module RESTFramework::BaseModelControllerMixin
|
|
125
125
|
def get_body_params
|
126
126
|
# Filter the request body and map to strings. Return all params if we cannot resolve a list of
|
127
127
|
# allowed parameters or fields.
|
128
|
-
|
128
|
+
allowed_params = self.get_allowed_parameters&.map(&:to_s)
|
129
|
+
body_params = if allowed_params
|
129
130
|
request.request_parameters.select { |p| allowed_params.include?(p) }
|
130
131
|
else
|
131
132
|
request.request_parameters
|
132
133
|
end
|
133
134
|
|
134
|
-
# Add query params in place of missing body params, if configured.
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
if (value = params[k])
|
135
|
+
# Add query params in place of missing body params, if configured.
|
136
|
+
if self.class.accept_generic_params_as_body_params && allowed_params
|
137
|
+
(allowed_params - body_params.keys).each do |k|
|
138
|
+
if value = params[k].presence
|
139
139
|
body_params[k] = value
|
140
140
|
end
|
141
141
|
end
|
@@ -238,10 +238,16 @@ module RESTFramework::ListModelMixin
|
|
238
238
|
|
239
239
|
# Handle pagination, if enabled.
|
240
240
|
if self.class.paginator_class
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
241
|
+
# If there is no `max_page_size`, `page_size_query_param` is not `nil`, and the page size is
|
242
|
+
# set to "0", then skip pagination.
|
243
|
+
unless !self.class.max_page_size &&
|
244
|
+
self.class.page_size_query_param &&
|
245
|
+
params[self.class.page_size_query_param] == "0"
|
246
|
+
paginator = self.class.paginator_class.new(data: records, controller: self)
|
247
|
+
page = paginator.get_page
|
248
|
+
serialized_page = self.serialize(page)
|
249
|
+
return paginator.get_paginated_response(serialized_page)
|
250
|
+
end
|
245
251
|
end
|
246
252
|
|
247
253
|
return records
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest_framework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregory N. Schmit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|