rest_framework 0.7.2 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rest_framework/controller_mixins/models.rb +16 -3
- data/lib/rest_framework/utils.rb +15 -2
- 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: 0343a285f928c169815684c0cbb0176fc1cc1781cb7f4208bb7ea3f756e11f17
|
4
|
+
data.tar.gz: 683fe62f24ecbeb83441e48b235f1842717722f4a48e861108faa91b6499f105
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33ca1398d2585b92741d4c005ae8fa2f88f320945befaf54b099c67882021d3a2357a5bca4cabfe95b31a90357c4cc83f8fad0d94e120db73a6538c3971b081d
|
7
|
+
data.tar.gz: 86b469abf36473dbecc5a90785b7d185655dc290ae14aa270d5a2019c61a9f3bda170689b9ef7c1983fd8ea918e59b3ec1af072c347baa614fd6c832ce287066
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.3
|
@@ -81,7 +81,7 @@ module RESTFramework::BaseModelControllerMixin
|
|
81
81
|
def get_fields_metadata(fields: nil)
|
82
82
|
# Get metadata sources.
|
83
83
|
model = self.get_model
|
84
|
-
fields ||= self.
|
84
|
+
fields ||= self.get_fields
|
85
85
|
fields = fields.map(&:to_s)
|
86
86
|
columns = model.columns_hash
|
87
87
|
column_defaults = model.column_defaults
|
@@ -244,14 +244,27 @@ module RESTFramework::BaseModelControllerMixin
|
|
244
244
|
return (action_config[action] if action) || self.class.send(generic_config_key)
|
245
245
|
end
|
246
246
|
|
247
|
+
# Get fields without any action context. Always fallback to columns at the class level.
|
248
|
+
def self.get_fields
|
249
|
+
if self.fields.is_a?(Hash)
|
250
|
+
return RESTFramework::Utils.parse_fields_hash(self.fields, self.get_model)
|
251
|
+
end
|
252
|
+
|
253
|
+
return self.fields || self.get_model&.column_names || []
|
254
|
+
end
|
255
|
+
|
247
256
|
# Get a list of fields for the current action. Returning `nil` indicates that anything should be
|
248
257
|
# accepted unless `fallback` is true, in which case we should fallback to this controller's model
|
249
258
|
# columns, or en empty array.
|
250
259
|
def get_fields(fallback: false)
|
251
260
|
fields = _get_specific_action_config(:action_fields, :fields)
|
252
261
|
|
253
|
-
|
254
|
-
|
262
|
+
# If fields is a hash, then parse using columns as a base, respecting `only` and `except`.
|
263
|
+
if fields.is_a?(Hash)
|
264
|
+
return RESTFramework::Utils.parse_fields_hash(fields, self.class.get_model)
|
265
|
+
elsif !fields && fallback
|
266
|
+
# Otherwise, if fields is nil and fallback is true, then fallback to columns.
|
267
|
+
return self.class.get_model&.column_names || []
|
255
268
|
end
|
256
269
|
|
257
270
|
return fields
|
data/lib/rest_framework/utils.rb
CHANGED
@@ -79,7 +79,7 @@ module RESTFramework::Utils
|
|
79
79
|
current_route ||= self.get_request_route(application_routes, request)
|
80
80
|
current_path = current_route.path.spec.to_s.gsub("(.:format)", "")
|
81
81
|
current_levels = current_path.count("/")
|
82
|
-
current_comparable_path = self.comparable_path(current_path)
|
82
|
+
current_comparable_path = %r{^#{Regexp.quote(self.comparable_path(current_path))}(/|$)}
|
83
83
|
|
84
84
|
# Add helpful properties of the current route.
|
85
85
|
path_args = current_route.required_parts.map { |n| request.path_parameters[n] }
|
@@ -96,7 +96,7 @@ module RESTFramework::Utils
|
|
96
96
|
# to show.
|
97
97
|
(
|
98
98
|
(r.defaults[:subdomain].blank? || r.defaults[:subdomain] == request.subdomain) &&
|
99
|
-
self.comparable_path(r.path.spec.to_s)
|
99
|
+
current_comparable_path.match?(self.comparable_path(r.path.spec.to_s)) &&
|
100
100
|
r.defaults[:controller].present? &&
|
101
101
|
r.defaults[:action].present?
|
102
102
|
)
|
@@ -137,4 +137,17 @@ module RESTFramework::Utils
|
|
137
137
|
|
138
138
|
return s
|
139
139
|
end
|
140
|
+
|
141
|
+
# Parse fields hashes.
|
142
|
+
def self.parse_fields_hash(fields_hash, model)
|
143
|
+
parsed_fields = fields_hash[:only] || model&.column_names || []
|
144
|
+
parsed_fields -= fields_hash[:except] if fields_hash[:except]
|
145
|
+
|
146
|
+
# Warn for any unknown keys.
|
147
|
+
(fields_hash.keys - [:only, :except]).each do |k|
|
148
|
+
Rails.logger.warn("RRF: Unknown key in fields hash: #{k}")
|
149
|
+
end
|
150
|
+
|
151
|
+
return parsed_fields
|
152
|
+
end
|
140
153
|
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.7.
|
4
|
+
version: 0.7.3
|
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: 2023-01-
|
11
|
+
date: 2023-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|