rest_framework 0.6.7 → 0.6.8

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: 4aef3d359b16de4e6980d055031a4eb1d1ebd3f9aafa39af6b9effec8e1319d2
4
- data.tar.gz: 5df89b3b8f9e6879cb6422d629743471e7641cb3b06736fdd7ddc583e6a5d182
3
+ metadata.gz: fc722756068a8151e2b84e0305b5484cb831c555ecd9a648af883d70e0196036
4
+ data.tar.gz: 4c5681012eb56285f7cce8baf6e8b6afb275857c69eab317c8aedb742aee62a2
5
5
  SHA512:
6
- metadata.gz: 01efb5108e191ad044fd64c61781cba2c2ea3e2a516f4cde1c7b3fec1fa7568ed29dda159a37440b1e59f59b6fbeb0754be4b4a37c86c0c4f94e10d81aa57ec4
7
- data.tar.gz: c5302e76238dbd5fc610a9b2bea424c62646d8766f23a2a7cfe9d22ac5f4f40db99901c448696f315347e9f358756fd0d373b2003a32288d327e6ec08fa1cf75
6
+ metadata.gz: 0cc9f1280add8372ae481168786f1069ab8026d81971a75aab809f5614abcef656a16e0386875402a85bf780d3223e22af81b764bbfd996a8003efdf4fbb63e5
7
+ data.tar.gz: f8f2a20341a8a418c7dec9bd4a3fdea907ee4778bf7d6ac1557b9a430fe97dfba2e6b1f7bee94a30ad944e8bc3fb5ff77b4030c6d4a3a955f8e7f7a9ee0bd4b2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.7
1
+ 0.6.8
@@ -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: true,
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
- # Helper to disable serializer adapters by default, mainly introduced because Active Model
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
- {message: "Record invalid.", exception: e, errors: e.record&.errors}, status: 400
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({message: "Record not found.", exception: e}, status: 404)
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
- {message: "Record not saved.", exception: e, errors: e.record&.errors}, status: 406
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
- {message: "Record not destroyed.", exception: e, errors: e.record&.errors}, status: 406
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
- body_params = if allowed_params = self.get_allowed_parameters&.map(&:to_s)
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. If fields are not defined,
135
- # fallback to using columns for this particular feature.
136
- if self.class.accept_generic_params_as_body_params
137
- (self.get_fields(fallback: true) - body_params.keys).each do |k|
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
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.7
4
+ version: 0.6.8
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-08 00:00:00.000000000 Z
11
+ date: 2022-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails