rest_framework 1.0.0.rc1 → 1.0.0

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.
@@ -1,9 +1,9 @@
1
1
  module RESTFramework::Utils
2
- HTTP_VERB_ORDERING = %w(GET POST PUT PATCH DELETE OPTIONS HEAD)
2
+ HTTP_VERB_ORDERING = %w[GET POST PUT PATCH DELETE OPTIONS HEAD]
3
3
 
4
4
  # Convert `extra_actions` hash to a consistent format: `{path:, methods:, metadata:, kwargs:}`.
5
5
  def self.parse_extra_actions(extra_actions)
6
- return (extra_actions || {}).map { |k, v|
6
+ (extra_actions || {}).map { |k, v|
7
7
  path = k
8
8
  kwargs = {}
9
9
 
@@ -13,7 +13,7 @@ module RESTFramework::Utils
13
13
  v = v.symbolize_keys
14
14
 
15
15
  # Cast method/methods to an array.
16
- methods = [v.delete(:methods), v.delete(:method)].flatten.compact
16
+ methods = [ v.delete(:methods), v.delete(:method) ].flatten.compact
17
17
 
18
18
  # Override path if it's provided.
19
19
  if v.key?(:path)
@@ -26,7 +26,7 @@ module RESTFramework::Utils
26
26
  # Pass any further kwargs to the underlying Rails interface.
27
27
  kwargs = v
28
28
  else
29
- methods = [v].flatten
29
+ methods = [ v ].flatten
30
30
  end
31
31
 
32
32
  next [
@@ -43,7 +43,7 @@ module RESTFramework::Utils
43
43
 
44
44
  # Get actions which should be skipped for a given controller.
45
45
  def self.get_skipped_builtin_actions(controller_class)
46
- return (
46
+ (
47
47
  RESTFramework::BUILTIN_ACTIONS.keys + RESTFramework::BUILTIN_MEMBER_ACTIONS.keys
48
48
  ).reject do |action|
49
49
  controller_class.method_defined?(action)
@@ -58,7 +58,7 @@ module RESTFramework::Utils
58
58
  # Normalize a path pattern by replacing URL params with generic placeholder, and removing the
59
59
  # `(.:format)` at the end.
60
60
  def self.comparable_path(path)
61
- return path.gsub("(.:format)", "").gsub(/:[0-9A-Za-z_-]+/, ":x")
61
+ path.gsub("(.:format)", "").gsub(/:[0-9A-Za-z_-]+/, ":x")
62
62
  end
63
63
 
64
64
  # Show routes under a controller action; used for the browsable API.
@@ -74,7 +74,7 @@ module RESTFramework::Utils
74
74
 
75
75
  # Return routes that match our current route subdomain/pattern, grouped by controller. We
76
76
  # precompute certain properties of the route for performance.
77
- return application_routes.routes.select { |r|
77
+ application_routes.routes.select { |r|
78
78
  # We `select` first to avoid unnecessarily calculating metadata for routes we don't even want
79
79
  # to show.
80
80
  (r.defaults[:subdomain].blank? || r.defaults[:subdomain] == request.subdomain) &&
@@ -100,7 +100,7 @@ module RESTFramework::Utils
100
100
  verb: r.verb,
101
101
  path: path,
102
102
  path_with_params: r.format(
103
- r.required_parts.each_with_index.map { |p, i| [p, path_params[i]] }.to_h,
103
+ r.required_parts.each_with_index.map { |p, i| [ p, path_params[i] ] }.to_h,
104
104
  ),
105
105
  relative_path: relative_path,
106
106
  concat_path: concat_path,
@@ -125,17 +125,17 @@ module RESTFramework::Utils
125
125
  # Sort the controller groups by current controller first, then alphanumerically.
126
126
  # Note: Use `controller_path` instead of `params[:controller]` to avoid re-raising a
127
127
  # `ActionDispatch::Http::Parameters::ParseError` exception.
128
- [request.controller_class.controller_path == c ? 0 : 1, c]
128
+ [ request.controller_class.controller_path == c ? 0 : 1, c ]
129
129
  }.to_h
130
130
  end
131
131
 
132
132
  # Custom inflector for RESTful controllers.
133
- def self.inflect(s, acronyms=nil)
133
+ def self.inflect(s, acronyms = nil)
134
134
  acronyms&.each do |acronym|
135
135
  s = s.gsub(/\b#{acronym}\b/i, acronym)
136
136
  end
137
137
 
138
- return s
138
+ s
139
139
  end
140
140
 
141
141
  # Parse fields hashes.
@@ -153,12 +153,12 @@ module RESTFramework::Utils
153
153
  parsed_fields -= h[:except].map(&:to_s) if h[:except]
154
154
 
155
155
  # Warn for any unknown keys.
156
- (h.keys - [:only, :except, :include, :exclude]).each do |k|
156
+ (h.keys - [ :only, :except, :include, :exclude ]).each do |k|
157
157
  Rails.logger.warn("RRF: Unknown key in fields hash: #{k}")
158
158
  end
159
159
 
160
160
  # We should always return strings, not symbols.
161
- return parsed_fields.map(&:to_s)
161
+ parsed_fields.map(&:to_s)
162
162
  end
163
163
 
164
164
  # Get the fields for a given model, including not just columns (which includes
@@ -181,7 +181,7 @@ module RESTFramework::Utils
181
181
  # Associations:
182
182
  associations = model.reflections.map { |association, ref|
183
183
  # Ignore associations for which we have custom integrations.
184
- if ref.class_name.in?(%w(ActionText::RichText ActiveStorage::Attachment ActiveStorage::Blob))
184
+ if ref.class_name.in?(%w[ActionText::RichText ActiveStorage::Attachment ActiveStorage::Blob])
185
185
  next nil
186
186
  end
187
187
 
@@ -194,29 +194,29 @@ module RESTFramework::Utils
194
194
  next association
195
195
  }.compact
196
196
 
197
- return base_fields + associations + atf + asf
197
+ base_fields + associations + atf + asf
198
198
  end
199
199
 
200
200
  # Get the sub-fields that may be serialized and filtered/ordered for a reflection.
201
201
  def self.sub_fields_for(ref)
202
202
  if !ref.polymorphic? && model = ref.klass
203
- sub_fields = [model.primary_key].flatten.compact
203
+ sub_fields = [ model.primary_key ].flatten.compact
204
204
  label_fields = RESTFramework.config.label_fields
205
205
 
206
206
  # Preferrably find a database column to use as label.
207
207
  if match = label_fields.find { |f| f.in?(model.column_names) }
208
- return sub_fields + [match]
208
+ return sub_fields + [ match ]
209
209
  end
210
210
 
211
211
  # Otherwise, find a method.
212
212
  if match = label_fields.find { |f| model.method_defined?(f) }
213
- return sub_fields + [match]
213
+ return sub_fields + [ match ]
214
214
  end
215
215
 
216
216
  return sub_fields
217
217
  end
218
218
 
219
- return ["id", "name"]
219
+ [ "id", "name" ]
220
220
  end
221
221
 
222
222
  # Get a field's id/ids variation.
@@ -229,7 +229,7 @@ module RESTFramework::Utils
229
229
  return reflection.foreign_key
230
230
  end
231
231
 
232
- return nil
232
+ nil
233
233
  end
234
234
 
235
235
  # Wrap a serializer with an adapter if it is an ActiveModel::Serializer.
@@ -238,6 +238,6 @@ module RESTFramework::Utils
238
238
  return RESTFramework::ActiveModelSerializerAdapterFactory.for(s)
239
239
  end
240
240
 
241
- return s
241
+ s
242
242
  end
243
243
  end
@@ -19,7 +19,7 @@ module RESTFramework
19
19
  end
20
20
 
21
21
  # No VERSION file, so version is unknown.
22
- return UNKNOWN
22
+ UNKNOWN
23
23
  end
24
24
 
25
25
  def self.stamp_version
@@ -9,14 +9,14 @@ module RESTFramework
9
9
  BUILTIN_MEMBER_ACTIONS = {
10
10
  show: :get,
11
11
  edit: :get,
12
- update: [:put, :patch].freeze,
12
+ update: [ :put, :patch ].freeze,
13
13
  destroy: :delete,
14
14
  }.freeze
15
15
  RRF_BUILTIN_ACTIONS = {
16
16
  options: :options,
17
17
  }.freeze
18
18
  RRF_BUILTIN_BULK_ACTIONS = {
19
- update_all: [:put, :patch].freeze,
19
+ update_all: [ :put, :patch ].freeze,
20
20
  destroy_all: :delete,
21
21
  }.freeze
22
22
 
@@ -65,12 +65,12 @@ module RESTFramework
65
65
  "highlight-a11y-dark.min.css" => {
66
66
  url: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.0/styles/a11y-dark.min.css",
67
67
  sri: "sha512-Vj6gPCk8EZlqnoveEyuGyYaWZ1+jyjMPg8g4shwyyNlRQl6d3L9At02ZHQr5K6s5duZl/+YKMnM3/8pDhoUphg==",
68
- extra_tag_attrs: {class: "rrf-dark-mode"},
68
+ extra_tag_attrs: { class: "rrf-dark-mode" },
69
69
  },
70
70
  "highlight-a11y-light.min.css" => {
71
71
  url: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.0/styles/a11y-light.min.css",
72
72
  sri: "sha512-WDk6RzwygsN9KecRHAfm9HTN87LQjqdygDmkHSJxVkVI7ErCZ8ZWxP6T8RvBujY1n2/E4Ac+bn2ChXnp5rnnHA==",
73
- extra_tag_attrs: {class: "rrf-light-mode"},
73
+ extra_tag_attrs: { class: "rrf-light-mode" },
74
74
  },
75
75
 
76
76
  # NeatJSON
@@ -117,7 +117,7 @@ module RESTFramework
117
117
  raise "Unknown asset extension: #{ext}."
118
118
  end
119
119
 
120
- [name, cfg]
120
+ [ name, cfg ]
121
121
  }.to_h.freeze
122
122
  # rubocop:enable Layout/LineLength
123
123
 
@@ -126,8 +126,8 @@ module RESTFramework
126
126
  # Global configuration should be kept minimal, as controller-level configurations allows multiple
127
127
  # APIs to be defined to behave differently.
128
128
  class Config
129
- DEFAULT_LABEL_FIELDS = %w(name label login title email username url).freeze
130
- DEFAULT_SEARCH_COLUMNS = DEFAULT_LABEL_FIELDS + %w(description note).freeze
129
+ DEFAULT_LABEL_FIELDS = %w[name label login title email username url].freeze
130
+ DEFAULT_SEARCH_COLUMNS = DEFAULT_LABEL_FIELDS + %w[description note].freeze
131
131
  DEFAULT_EXCLUDE_BODY_FIELDS = %w[
132
132
  created_at
133
133
  created_by
@@ -192,7 +192,7 @@ module RESTFramework
192
192
  end
193
193
 
194
194
  def self.config
195
- return @config ||= Config.new
195
+ @config ||= Config.new
196
196
  end
197
197
 
198
198
  def self.configure
@@ -200,7 +200,7 @@ module RESTFramework
200
200
  end
201
201
 
202
202
  def self.features
203
- return @features ||= {}
203
+ @features ||= {}
204
204
  end
205
205
  end
206
206
 
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: 1.0.0.rc1
4
+ version: 1.0.0
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: 2025-04-24 00:00:00.000000000 Z
11
+ date: 2025-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -96,12 +96,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
96
  requirements:
97
97
  - - ">="
98
98
  - !ruby/object:Gem::Version
99
- version: 2.3.0
99
+ version: 2.7.5
100
100
  required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - ">"
102
+ - - ">="
103
103
  - !ruby/object:Gem::Version
104
- version: 1.3.1
104
+ version: '0'
105
105
  requirements: []
106
106
  rubygems_version: 3.4.10
107
107
  signing_key: