rest_framework 0.8.6 → 0.8.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4fe6c7cddb11163195ca847ef985d87274b20b33a16bba96ed1979dd9ef3f91
4
- data.tar.gz: e9db88d728e115a1e20d9584087fb21f48cff195476019efefa7f19c142eeb9e
3
+ metadata.gz: fdf558252b808d2206ef0998357d81ccab85d81da850e8d3fb6b881c8a6919b8
4
+ data.tar.gz: 11bb1d4d4aeee303e691001694a9dc637b78f3f6b0a554f5945ee0ccd1ce0227
5
5
  SHA512:
6
- metadata.gz: 3c6a447cedc65be69c0ab0ae9430ecd219e6780b1373ba3cecfecc57d7335cf9af388a996e8d57f9b16cce60fc941f02d940b88f29e78841fb9eb78f4746b1d2
7
- data.tar.gz: 2c187d7b063b084970b3d8e8d13699e0c6e321cf4d4c38d23357923b9a0c10ea5fa9bd54763959913d772745d6aa5abfbaa7f8ad6fd79162c1724a5d696cfa19
6
+ metadata.gz: a62aa886dac641f1635f41c8dfa659c3ddbc706d594ec3e58182241493b7294c58623be1aaa01010ec5f7473c6a64c887a582f1205ab560a1d05ddde00fe1a14
7
+ data.tar.gz: e7e4f071815949810711be85bef6a5499f78fdf81f8cd872b7834e853f463313403f45877c0ae2f979eda23b6f33c55e768ce34941095e66ea3f4edbc0886d56
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.6
1
+ 0.8.8
@@ -71,7 +71,7 @@ module RESTFramework::BaseModelControllerMixin
71
71
  IGNORE_VALIDATORS_WITH_KEYS = [:if, :unless].freeze
72
72
 
73
73
  # Get the model for this controller.
74
- def get_model(from_get_recordset: false)
74
+ def get_model
75
75
  return @model if @model
76
76
  return (@model = self.model) if self.model
77
77
 
@@ -81,19 +81,7 @@ module RESTFramework::BaseModelControllerMixin
81
81
  rescue NameError
82
82
  end
83
83
 
84
- # Delegate to the recordset's model, if it's defined. This option prevents infinite recursion.
85
- unless from_get_recordset
86
- # Instantiate a new controller to get the recordset.
87
- controller = self.new
88
- controller.request = ActionController::TestRequest.new
89
- controller.params = {}
90
-
91
- if (recordset = controller.get_recordset)
92
- return @model = recordset.klass
93
- end
94
- end
95
-
96
- return nil
84
+ raise RESTFramework::UnknownModelError, self
97
85
  end
98
86
 
99
87
  # Override `get_label` to include ActiveRecord i18n-translated column names.
@@ -207,6 +195,12 @@ module RESTFramework::BaseModelControllerMixin
207
195
  # Get enum variants.
208
196
  if type.is_a?(ActiveRecord::Enum::EnumType)
209
197
  metadata[:enum_variants] = type.send(:mapping)
198
+
199
+ # Custom integration with `translate_enum`.
200
+ translate_method = "translated_#{f.pluralize}"
201
+ if model.respond_to?(translate_method)
202
+ metadata[:enum_translations] = model.send(translate_method)
203
+ end
210
204
  end
211
205
  end
212
206
  end
@@ -482,7 +476,7 @@ module RESTFramework::BaseModelControllerMixin
482
476
  return (@recordset = self.class.recordset) if self.class.recordset
483
477
 
484
478
  # If there is a model, return that model's default scope (all records by default).
485
- if (model = self.class.get_model(from_get_recordset: true))
479
+ if (model = self.class.get_model)
486
480
  return @recordset = model.all
487
481
  end
488
482
 
@@ -13,3 +13,19 @@ class RESTFramework::NilPassedToAPIResponseError < RESTFramework::Error
13
13
  MSG
14
14
  end
15
15
  end
16
+
17
+ class RESTFramework::UnknownModelError < RESTFramework::Error
18
+ def initialize(controller_class)
19
+ super()
20
+ @controller_class = controller_class
21
+ end
22
+
23
+ def message
24
+ return <<~MSG.split("\n").join(" ")
25
+ The model class for `#{@controller_class}` could not be determined. Any controller that
26
+ includes `RESTFramework::BaseModelControllerMixin` (directly or indirectly) must either set
27
+ the `model` attribute on the controller, or the model must be deducible from the controller
28
+ name (e.g., `UsersController` could resolve to the `User` model).
29
+ MSG
30
+ end
31
+ end
@@ -115,8 +115,6 @@ end
115
115
 
116
116
  # Multi-field text searching on models.
117
117
  class RESTFramework::ModelSearchFilter < RESTFramework::BaseFilter
118
- DEFAULT_SEARCH_COLUMNS = %w[name email title description note]
119
-
120
118
  # Get a list of search fields for the current action. Fallback to columns but only grab a few
121
119
  # common string-like columns by default.
122
120
  def _get_fields
@@ -126,7 +124,7 @@ class RESTFramework::ModelSearchFilter < RESTFramework::BaseFilter
126
124
 
127
125
  columns = @controller.class.get_model.columns_hash.keys
128
126
  return @controller.get_fields(fallback: true).select { |f|
129
- f.in?(DEFAULT_SEARCH_COLUMNS) && f.in?(columns)
127
+ f.in?(RESTFramework.config.search_columns) && f.in?(columns)
130
128
  }
131
129
  end
132
130
 
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.8.6
4
+ version: 0.8.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: 2023-02-03 00:00:00.000000000 Z
11
+ date: 2023-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails