typed_params 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +6 -4
- data/lib/typed_params/formatters/jsonapi.rb +3 -3
- data/lib/typed_params/schema.rb +1 -4
- data/lib/typed_params/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f82d6c1b5e74e9768d4e039ffdb562d4f4358a3cacdcaa6bbd7c88fa2f052b98
|
4
|
+
data.tar.gz: a2635ee1541b834a73cefed0768f15e9d47d435af3b3d27cb497d0d4e98bb18a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dfb4c39029e273c58a08459b2c7fc2b5263947816d15bcb4a3e8d3e8b9bd2b7ca56b487f40b8d84a4bd391b6cf7913717be2c62e7d38548e8f8cea4c93e4ec8
|
7
|
+
data.tar.gz: 444e92938c7426fec891eda9f7dd226861296f6159c1e8905d6776d2fee75c95f20ce762358161c36970bf84ceadbc352d0bfdfb6c7f56f9c1d350934ba86649
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -689,8 +689,10 @@ param :invalid, type: :string, validate: -> v {
|
|
689
689
|
|
690
690
|
#### Polymorphic parameter
|
691
691
|
|
692
|
-
|
693
|
-
|
692
|
+
_Note: currently, this option is only utilized by the JSONAPI formatter._
|
693
|
+
|
694
|
+
Define a polymorphic parameter. Actual behavior will vary based on the
|
695
|
+
formatter being used.
|
694
696
|
|
695
697
|
```ruby
|
696
698
|
format :jsonapi
|
@@ -711,8 +713,8 @@ typed_params # => { owner_type: 'User', owner_id: 1 }
|
|
711
713
|
|
712
714
|
In this example, a polymorphic `:owner` relationship is defined. When run
|
713
715
|
through the JSONAPI formatter, instead of formatting the relationship
|
714
|
-
into the `:owner_id` key, it also includes the `:owner_type`
|
715
|
-
for a polymorphic association.
|
716
|
+
into solely the `:owner_id` key, it also includes the `:owner_type`
|
717
|
+
key for a polymorphic association.
|
716
718
|
|
717
719
|
### Shared options
|
718
720
|
|
@@ -77,7 +77,8 @@ module TypedParams
|
|
77
77
|
# relationship data only contains :type and :id, otherwise it
|
78
78
|
# will use the x_attributes key.
|
79
79
|
rels&.each do |key, rel|
|
80
|
-
child = schema.children.
|
80
|
+
child = schema.children.fetch(:relationships)
|
81
|
+
.children.fetch(key)
|
81
82
|
|
82
83
|
case rel
|
83
84
|
# FIXME(ezekg) We need https://bugs.ruby-lang.org/issues/18961 to
|
@@ -86,8 +87,7 @@ module TypedParams
|
|
86
87
|
res[:"#{key.to_s.singularize}_ids"] = linkage.map { _1[:id] }
|
87
88
|
in data: []
|
88
89
|
res[:"#{key.to_s.singularize}_ids"] = []
|
89
|
-
|
90
|
-
in data: { type:, id:, **nil } if key.to_s.underscore.classify != type.underscore.classify && child.polymorphic?
|
90
|
+
in data: { type:, id:, **nil } if child.polymorphic?
|
91
91
|
res[:"#{key}_type"], res[:"#{key}_id"] = type.underscore.classify, id
|
92
92
|
in data: { type:, id:, **nil }
|
93
93
|
res[:"#{key}_id"] = id
|
data/lib/typed_params/schema.rb
CHANGED
@@ -272,7 +272,7 @@ module TypedParams
|
|
272
272
|
def allow_nil? = !!@allow_nil
|
273
273
|
def allow_non_scalars? = !!@allow_non_scalars
|
274
274
|
def nilify_blanks? = !!@nilify_blanks
|
275
|
-
def endless?
|
275
|
+
def endless? = !!@endless
|
276
276
|
def indexed? = !endless?
|
277
277
|
def if? = !@if.nil?
|
278
278
|
def unless? = !@unless.nil?
|
@@ -285,9 +285,6 @@ module TypedParams
|
|
285
285
|
"#<#{self.class.name} key=#{key.inspect} type=#{type.inspect} children=#{children.inspect}>"
|
286
286
|
end
|
287
287
|
|
288
|
-
# @private
|
289
|
-
def dig(*keys) = children.dig(*keys)
|
290
|
-
|
291
288
|
private
|
292
289
|
|
293
290
|
attr_reader :controller,
|
data/lib/typed_params/version.rb
CHANGED