rest_framework 0.6.6 → 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: 88e17bbb8855d22fd7f73d637059d35bd12cc3fc9d982fbde73e11097b66af17
4
- data.tar.gz: 8fe97e8557a9c957b3a31b51b89c4a7623e97c2fbc75c9c8b80bb23b54dc8429
3
+ metadata.gz: fc722756068a8151e2b84e0305b5484cb831c555ecd9a648af883d70e0196036
4
+ data.tar.gz: 4c5681012eb56285f7cce8baf6e8b6afb275857c69eab317c8aedb742aee62a2
5
5
  SHA512:
6
- metadata.gz: 5362740a21ef0ef6248c36783da74ff5ad0b142ea9d2de7e228d5052d9badc7af3f78e259dba1015112c04379fd17c16265b0843c26cc2654e89a1742f53e051
7
- data.tar.gz: 61d6ac5dca5113be086b9e3232e1e7c2e3fa26d45634764993c474cffcc62403f5285b9da0ebdcfd69b4dbe0b9fedaaa5f9d30d2366286a71c458fdbc9fe4ef7
6
+ metadata.gz: 0cc9f1280add8372ae481168786f1069ab8026d81971a75aab809f5614abcef656a16e0386875402a85bf780d3223e22af81b764bbfd996a8003efdf4fbb63e5
7
+ data.tar.gz: f8f2a20341a8a418c7dec9bd4a3fdea907ee4778bf7d6ac1557b9a430fe97dfba2e6b1f7bee94a30ad944e8bc3fb5ff77b4030c6d4a3a955f8e7f7a9ee0bd4b2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.6
1
+ 0.6.8
@@ -73,7 +73,7 @@
73
73
  </div>
74
74
  <% if @json_payload.present? || @xml_payload.present? %>
75
75
  <div class="row">
76
- <div class="w-100">
76
+ <div>
77
77
  <ul class="nav nav-tabs">
78
78
  <% if @json_payload.present? %>
79
79
  <li class="nav-item">
@@ -91,7 +91,7 @@
91
91
  <% end %>
92
92
  </ul>
93
93
  </div>
94
- <div class="tab-content w-100 pt-3">
94
+ <div class="tab-content pt-2">
95
95
  <div class="tab-pane fade show active" id="tab-json" role="tab">
96
96
  <% if @json_payload.present? %>
97
97
  <div>
@@ -109,7 +109,7 @@
109
109
  <% end %>
110
110
  <% if @route_groups.present? %>
111
111
  <div class="row">
112
- <div class="w-100">
112
+ <div>
113
113
  <ul class="nav nav-tabs">
114
114
  <li class="nav-item">
115
115
  <a class="nav-link active" href="#tab-routes" data-bs-toggle="tab" role="tab">
@@ -128,7 +128,7 @@
128
128
  <% end %>
129
129
  </ul>
130
130
  </div>
131
- <div class="tab-content w-100 pt-3">
131
+ <div class="tab-content pt-2">
132
132
  <div class="tab-pane fade show active" id="tab-routes" role="tab">
133
133
  <%= render partial: 'rest_framework/routes' %>
134
134
  </div>
@@ -18,7 +18,7 @@ h6 { font-size: 1rem; }
18
18
  /* Make code and code blocks a little nicer looking. */
19
19
  code {
20
20
  padding: 0 .35em;
21
- background-color: #eee !important;
21
+ background-color: #f3f3f3 !important;
22
22
  border: 1px solid #aaa;
23
23
  border-radius: 3px;
24
24
  }
@@ -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
@@ -86,7 +86,7 @@ class RESTFramework::ModelSearchFilter < RESTFramework::BaseFilter
86
86
  unless search.blank?
87
87
  return data.where(
88
88
  fields.map { |f|
89
- "CAST(#{f} AS CHAR) #{@controller.class.search_ilike ? "ILIKE" : "LIKE"} ?"
89
+ "CAST(#{f} AS VARCHAR) #{@controller.class.search_ilike ? "ILIKE" : "LIKE"} ?"
90
90
  }.join(" OR "),
91
91
  *(["%#{search}%"] * fields.length),
92
92
  )
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.6
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-07 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