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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 014c42e82286c1ffc175d08aca51e631da96a5b2aee8e9bbf575fc0bea7e1d57
4
- data.tar.gz: 3a0ea8bac6b1021143b768767763899a6f5328f16bb6011a87b2f1ed694b6325
3
+ metadata.gz: f82d6c1b5e74e9768d4e039ffdb562d4f4358a3cacdcaa6bbd7c88fa2f052b98
4
+ data.tar.gz: a2635ee1541b834a73cefed0768f15e9d47d435af3b3d27cb497d0d4e98bb18a
5
5
  SHA512:
6
- metadata.gz: c563758456e6359e37c75926124925141c59f535fc77070be23d46d3f86e0772f2cf2c52d2e57f165e2ba11f93717c6a0b15f90e61fcbe00baa19b3c1985f2a8
7
- data.tar.gz: a277c1c13a5d0ac14ef293fbc9611bec82eba5df00686f9afaf8e324e89148aef7c49fa672bf025570a9482ec277e330edc1049a1e59051e41a559a31a4b6584
6
+ metadata.gz: 6dfb4c39029e273c58a08459b2c7fc2b5263947816d15bcb4a3e8d3e8b9bd2b7ca56b487f40b8d84a4bd391b6cf7913717be2c62e7d38548e8f8cea4c93e4ec8
7
+ data.tar.gz: 444e92938c7426fec891eda9f7dd226861296f6159c1e8905d6776d2fee75c95f20ce762358161c36970bf84ceadbc352d0bfdfb6c7f56f9c1d350934ba86649
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.1
4
+
5
+ - Update JSONAPI formatter to simplify logic for polymorphic relationships.
6
+
3
7
  ## 1.2.0
4
8
 
5
9
  - Add `aliases:` keyword to `#param` to allow the schema to be accessible by different names.
data/README.md CHANGED
@@ -689,8 +689,10 @@ param :invalid, type: :string, validate: -> v {
689
689
 
690
690
  #### Polymorphic parameter
691
691
 
692
- ***Currently, this option is only utilized by the JSONAPI formatter. Define
693
- a polymorphic parameter, used when formatting JSONAPI relationships.***
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` key
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.dig(:relationships, key)
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
- # FIXME(ezekg) Not sure how to make this cleaner, but this handles polymorphic relationships.
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
@@ -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? = !!@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,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TypedParams
4
- VERSION = '1.2.0'
4
+ VERSION = '1.2.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typed_params
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zeke Gabrielse