rhino_project_core 0.21.0.beta.46 → 0.21.0.beta.49
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/rhino/error_handling.rb +7 -5
- data/lib/rhino/resource/active_record_extension/params.rb +8 -3
- data/lib/rhino/resource/active_record_extension/properties_describe.rb +22 -8
- data/lib/rhino/resource/active_record_tree.rb +1 -1
- data/lib/rhino/version.rb +1 -1
- 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: 6a0a1268174a345a44c60dd808ba573367ca96eb00ff851d924fd802c7374eee
|
4
|
+
data.tar.gz: ea08c48496d0a9e162fefcf2b2935abfedd04461a92c5f8cf75e7bc33d80ad2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acc3ec16ca3703b080b3550e14d705c74dc37bc1f8c83f40087c3636b26b754f515c50f02db9f64aeb7264bb3feb019726543085d98f0f126bd98bff105b8c96
|
7
|
+
data.tar.gz: 436788e9e25fb8d609b72c6b7c03327708cf87d7d3454f7def601908041a8db4014b9715b7c98d7d803de1e70d79622188687956c4520c9208add8c9dd39c1fe
|
@@ -23,14 +23,16 @@ module Rhino
|
|
23
23
|
|
24
24
|
rescue_from ActiveRecord::RecordNotFound, with: :not_found
|
25
25
|
|
26
|
-
def handle_uncaught_error(
|
26
|
+
def handle_uncaught_error(e)
|
27
|
+
raise e if Rails.env.test?
|
28
|
+
|
27
29
|
# Send to rollbar if available
|
28
|
-
Rollbar.error(
|
30
|
+
Rollbar.error(e) if defined? Rollbar
|
29
31
|
|
30
|
-
logger.error
|
32
|
+
logger.error "There was an exception - #{e.class}(#{e.message})"
|
33
|
+
logger.error e.backtrace.join("\n")
|
31
34
|
|
32
|
-
render json: { errors: ['Internal server error.'] },
|
33
|
-
status: :internal_server_error
|
35
|
+
render json: { errors: ['Internal server error.'] }, status: :internal_server_error
|
34
36
|
end
|
35
37
|
|
36
38
|
def not_found
|
@@ -154,7 +154,7 @@ module Rhino
|
|
154
154
|
# rubocop:todo Metrics/CyclomaticComplexity
|
155
155
|
def transform_params_recursive(params, parent = self) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/PerceivedComplexity
|
156
156
|
hash = {}
|
157
|
-
params.each do |param_key, param_value|
|
157
|
+
params.each do |param_key, param_value| # rubocop:todo Metrics/BlockLength
|
158
158
|
association = parent.reflect_on_association(param_key)
|
159
159
|
|
160
160
|
# Its a regular attribute
|
@@ -187,19 +187,24 @@ module Rhino
|
|
187
187
|
# if its a cardinal though, such as blog: 1 instead of blog: {name : 'my blog' }
|
188
188
|
# fallback to transforming to the foreign key
|
189
189
|
if param_value.is_a?(ActionController::Parameters)
|
190
|
+
assoc = parent.reflections[param_key]
|
190
191
|
klasses = assoc_from_sym(param_key, parent)
|
191
192
|
|
193
|
+
# We only want to transform the params for the klass that matches the foreign_type
|
194
|
+
klasses.select! { |k| k.name == params[assoc.foreign_type] } if assoc.polymorphic?
|
195
|
+
|
192
196
|
next hash[attr_key] = klasses.map { |klass| parent.transform_params_recursive(param_value, klass) }.reduce(:merge)
|
193
197
|
end
|
194
198
|
end
|
195
199
|
|
196
200
|
# Map association name to foreign key, ie blog => blog_id
|
197
201
|
# or blog: { id: } => blog_id
|
198
|
-
if param_value.is_a?(ActionController::Parameters)
|
202
|
+
if param_value.is_a?(ActionController::Parameters) && !association.has_one?
|
199
203
|
next hash[association.foreign_key] = param_value[association.klass.identifier_property]
|
200
204
|
end
|
201
205
|
|
202
|
-
|
206
|
+
# If its a has_one, there is no foreign key on this model
|
207
|
+
hash[association.foreign_key] = param_value unless association.has_one?
|
203
208
|
end
|
204
209
|
|
205
210
|
# Force permit since we should have already been permitted at this point
|
@@ -8,6 +8,20 @@ module Rhino
|
|
8
8
|
module PropertiesDescribe # rubocop:disable Metrics/ModuleLength
|
9
9
|
extend ActiveSupport::Concern
|
10
10
|
|
11
|
+
class PolymorphicModelName
|
12
|
+
include ActiveSupport::Inflector
|
13
|
+
|
14
|
+
attr_reader :name
|
15
|
+
|
16
|
+
def initialize(name)
|
17
|
+
@name = name.to_s
|
18
|
+
end
|
19
|
+
|
20
|
+
def singular
|
21
|
+
underscore(name).tr("/", "_").singularize
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
11
25
|
class_methods do # rubocop:disable Metrics/BlockLength
|
12
26
|
def describe_property(property) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
13
27
|
name = property_name(property).to_s
|
@@ -43,7 +57,7 @@ module Rhino
|
|
43
57
|
def ref_descriptor(names)
|
44
58
|
{
|
45
59
|
type: :reference,
|
46
|
-
anyOf: names.map { |name| { :$ref => "#/components/schemas/#{name.
|
60
|
+
anyOf: names.map { |name| { :$ref => "#/components/schemas/#{name.singular}" } }
|
47
61
|
}
|
48
62
|
end
|
49
63
|
|
@@ -86,19 +100,19 @@ module Rhino
|
|
86
100
|
|
87
101
|
# rubocop:todo Metrics/PerceivedComplexity
|
88
102
|
# rubocop:todo Metrics/AbcSize
|
89
|
-
def property_type_and_format_ref(name) # rubocop:todo Metrics/
|
103
|
+
def property_type_and_format_ref(name) # rubocop:todo Metrics/AbcSize
|
90
104
|
assoc = reflections[name]
|
91
|
-
klasses = if assoc.
|
92
|
-
#
|
105
|
+
klasses = if assoc.polymorphic?
|
106
|
+
# Delegated type
|
93
107
|
if assoc.active_record.respond_to?("#{assoc.name}_types")
|
94
|
-
assoc.active_record.send("#{assoc.name}_types").map
|
108
|
+
assoc.active_record.send(:"#{assoc.name}_types").map { |x| x.constantize.model_name }
|
95
109
|
else
|
96
110
|
# FIXME: This is wrong, but there is no good way to introspect general polymorphic models
|
97
|
-
|
111
|
+
# FIXME: This should be an OpenAPI discriminator with all possible types (all models)
|
112
|
+
[PolymorphicModelName.new(name)]
|
98
113
|
end
|
99
114
|
else
|
100
|
-
|
101
|
-
[assoc.options[:class_name]&.underscore&.tr("/", "_") || name]
|
115
|
+
[assoc.klass.model_name]
|
102
116
|
end
|
103
117
|
|
104
118
|
return ref_descriptor(klasses) unless reflections[name].macro == :has_many
|
@@ -20,7 +20,7 @@ module Rhino
|
|
20
20
|
def describe_property(property)
|
21
21
|
return super unless property == "children"
|
22
22
|
|
23
|
-
super.deep_merge({ type: :array, items: ref_descriptor([model_name
|
23
|
+
super.deep_merge({ type: :array, items: ref_descriptor([model_name]) })
|
24
24
|
end
|
25
25
|
|
26
26
|
# FIXME: Need to recurse to a MAX DEPTH
|
data/lib/rhino/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rhino_project_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.21.0.beta.
|
4
|
+
version: 0.21.0.beta.49
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JP Rosevear
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|