rest_framework 1.0.2 → 1.1.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.
@@ -113,12 +113,17 @@ module ActionDispatch::Routing
113
113
  end
114
114
  end
115
115
 
116
- # Route bulk actions, if configured.
117
- RESTFramework::RRF_BUILTIN_BULK_ACTIONS.each do |action, methods|
118
- next unless controller_class.method_defined?(action)
119
-
120
- [ methods ].flatten.each do |m|
121
- public_send(m, "", action: action) if self.respond_to?(m)
116
+ # Route bulk actions, if configured. These require a model and are gated by the `bulk`
117
+ # attribute, and may be individually excluded via `excluded_actions`.
118
+ if controller_class.model && controller_class.bulk
119
+ bulk_exclude = controller_class.excluded_actions&.to_set || Set.new
120
+ RESTFramework::RRF_BUILTIN_BULK_ACTIONS.each do |action, methods|
121
+ next unless controller_class.method_defined?(action)
122
+ next if bulk_exclude.include?(action)
123
+
124
+ [ methods ].flatten.each do |m|
125
+ public_send(m, "", action: action) if self.respond_to?(m)
126
+ end
122
127
  end
123
128
  end
124
129
  end
@@ -31,7 +31,7 @@ class RESTFramework::Serializers::NativeSerializer < RESTFramework::Serializers:
31
31
  @model ||= @object[0].class if
32
32
  @many && @object.is_a?(Enumerable) && @object.is_a?(ActiveRecord::Base)
33
33
 
34
- @model ||= @controller.class.get_model if @controller
34
+ @model ||= @controller.class.model if @controller
35
35
  end
36
36
 
37
37
  def action
@@ -42,12 +42,15 @@ module RESTFramework::Utils
42
42
  end
43
43
 
44
44
  def self.get_skipped_builtin_actions(controller_class, singular)
45
- (
46
- (
47
- RESTFramework::BUILTIN_ACTIONS.keys - (singular ? [ :index ] : [])
48
- ) + RESTFramework::BUILTIN_MEMBER_ACTIONS.keys
49
- ).reject do |action|
50
- controller_class.method_defined?(action)
45
+ candidates = (
46
+ RESTFramework::BUILTIN_ACTIONS.keys - (singular ? [ :index ] : [])
47
+ ) + RESTFramework::BUILTIN_MEMBER_ACTIONS.keys
48
+
49
+ return candidates unless controller_class.model
50
+
51
+ exclude = controller_class.excluded_actions&.to_set || Set.new
52
+ candidates.reject do |action|
53
+ controller_class.method_defined?(action) && !exclude.include?(action)
51
54
  end
52
55
  end
53
56
 
@@ -241,4 +244,12 @@ module RESTFramework::Utils
241
244
 
242
245
  s
243
246
  end
247
+
248
+ # Used for deprecated mixins that rely on model being determined from the controller name.
249
+ def self.get_model(controller_class)
250
+ begin
251
+ controller_class.name.demodulize.chomp("Controller").singularize.constantize
252
+ rescue NameError
253
+ end
254
+ end
244
255
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RESTFramework
4
- BUILTIN_FORM_ACTIONS = %i[new edit].freeze
4
+ BUILTIN_FORM_ACTIONS = [ :new, :edit ].freeze
5
5
  BUILTIN_ACTIONS = {
6
6
  index: :get,
7
7
  new: :get,
@@ -144,6 +144,7 @@ module RESTFramework
144
144
  password
145
145
  password_confirmation
146
146
  ].freeze
147
+ DEFAULT_INFLECT_ACRONYMS = [ "ID", "IDs", "REST", "API", "APIs" ].freeze
147
148
 
148
149
  # Permits use of `render(api: obj)` syntax over `render_api(obj)`; `true` by default.
149
150
  attr_accessor :register_api_renderer
@@ -181,6 +182,9 @@ module RESTFramework
181
182
  attr_accessor :read_only_fields
182
183
  attr_accessor :write_only_fields
183
184
 
185
+ # List of acronyms to be inflected in controller titles and field labels.
186
+ attr_accessor :inflect_acronyms
187
+
184
188
  # Option to use vendored assets (requires sprockets or propshaft) rather than linking to
185
189
  # external assets (the default).
186
190
  attr_accessor :use_vendored_assets
@@ -195,6 +199,7 @@ module RESTFramework
195
199
  self.search_columns = DEFAULT_SEARCH_COLUMNS
196
200
  self.read_only_fields = DEFAULT_READ_ONLY_FIELDS
197
201
  self.write_only_fields = DEFAULT_WRITE_ONLY_FIELDS
202
+ self.inflect_acronyms = DEFAULT_INFLECT_ACRONYMS
198
203
  end
199
204
  end
200
205
 
@@ -209,6 +214,10 @@ module RESTFramework
209
214
  def self.features
210
215
  @features ||= {}
211
216
  end
217
+
218
+ def self.deprecator
219
+ @deprecator ||= ActiveSupport::Deprecation.new("2.0", "REST Framework")
220
+ end
212
221
  end
213
222
 
214
223
  require_relative "rest_framework/engine"
@@ -221,3 +230,5 @@ require_relative "rest_framework/routers"
221
230
  require_relative "rest_framework/serializers"
222
231
  require_relative "rest_framework/utils"
223
232
  require_relative "rest_framework/version"
233
+
234
+ require_relative "rest_framework/controller"
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.2
4
+ version: 1.1.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: 2026-04-13 00:00:00.000000000 Z
11
+ date: 2026-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -54,11 +54,14 @@ files:
54
54
  - app/views/rest_framework/routes_and_forms/_routes.html.erb
55
55
  - app/views/rest_framework/routes_and_forms/routes/_route.html.erb
56
56
  - lib/rest_framework.rb
57
+ - lib/rest_framework/controller.rb
58
+ - lib/rest_framework/controller/bulk.rb
59
+ - lib/rest_framework/controller/crud.rb
60
+ - lib/rest_framework/controller/openapi.rb
57
61
  - lib/rest_framework/engine.rb
58
62
  - lib/rest_framework/errors.rb
59
63
  - lib/rest_framework/errors/base_error.rb
60
64
  - lib/rest_framework/errors/nil_passed_to_render_api_error.rb
61
- - lib/rest_framework/errors/unknown_model_error.rb
62
65
  - lib/rest_framework/filters.rb
63
66
  - lib/rest_framework/filters/base_filter.rb
64
67
  - lib/rest_framework/filters/ordering_filter.rb
@@ -1,18 +0,0 @@
1
- class RESTFramework::Errors::UnknownModelError < RESTFramework::Errors::BaseError
2
- def initialize(controller_class)
3
- super()
4
- @controller_class = controller_class
5
- end
6
-
7
- def message
8
- <<~MSG.split("\n").join(" ")
9
- The model class for `#{@controller_class}` could not be determined. Any controller that
10
- includes `RESTFramework::BaseModelControllerMixin` (directly or indirectly) must either set
11
- the `model` attribute on the controller, or the model must be deducible from the controller
12
- name (e.g., `UsersController` could resolve to the `User` model).
13
- MSG
14
- end
15
- end
16
-
17
- # Alias for convenience.
18
- RESTFramework::UnknownModelError = RESTFramework::Errors::UnknownModelError