rest_framework 0.7.2 → 0.7.3

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: 6e34db1e862327396b55e22abc5431e1b2679944c109e3313167bb387860c42c
4
- data.tar.gz: 45597aaf31d61d53ffcfcebd632444cb1c69bf959f94647192d1749917fd5ff8
3
+ metadata.gz: 0343a285f928c169815684c0cbb0176fc1cc1781cb7f4208bb7ea3f756e11f17
4
+ data.tar.gz: 683fe62f24ecbeb83441e48b235f1842717722f4a48e861108faa91b6499f105
5
5
  SHA512:
6
- metadata.gz: 53ba45cf9b152c71c2db719e4f41890632e9f438f127ad6380d08e101a207eca5ef14b00c625de58854e618b410ac9709770687094cf6e2df5f7eb9ebd8814b4
7
- data.tar.gz: 9552f475a0b11c8573825a4132e8683aad6943a2012f261b86538628c0c344d5755d8806629310e0162e77b9553cc4bf854c2d54170d8b5b4b80ab77c98ee87d
6
+ metadata.gz: 33ca1398d2585b92741d4c005ae8fa2f88f320945befaf54b099c67882021d3a2357a5bca4cabfe95b31a90357c4cc83f8fad0d94e120db73a6538c3971b081d
7
+ data.tar.gz: 86b469abf36473dbecc5a90785b7d185655dc290ae14aa270d5a2019c61a9f3bda170689b9ef7c1983fd8ea918e59b3ec1af072c347baa614fd6c832ce287066
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.2
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.fields || model.column_names || []
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
- if fallback
254
- fields ||= self.class.get_model&.column_names || []
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
@@ -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).start_with?(current_comparable_path) &&
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.2
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-05 00:00:00.000000000 Z
11
+ date: 2023-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails