typed_params 1.2.1 → 1.2.2

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: f82d6c1b5e74e9768d4e039ffdb562d4f4358a3cacdcaa6bbd7c88fa2f052b98
4
- data.tar.gz: a2635ee1541b834a73cefed0768f15e9d47d435af3b3d27cb497d0d4e98bb18a
3
+ metadata.gz: 160a6e63cc497232a6c33d2cdc06050682c44e71624bee8d70f72e25b3ef3374
4
+ data.tar.gz: f0e1c30200d4ac4fc555cd5418546ed3ceba69dc54b09a98a02e4b349dcfd014
5
5
  SHA512:
6
- metadata.gz: 6dfb4c39029e273c58a08459b2c7fc2b5263947816d15bcb4a3e8d3e8b9bd2b7ca56b487f40b8d84a4bd391b6cf7913717be2c62e7d38548e8f8cea4c93e4ec8
7
- data.tar.gz: 444e92938c7426fec891eda9f7dd226861296f6159c1e8905d6776d2fee75c95f20ce762358161c36970bf84ceadbc352d0bfdfb6c7f56f9c1d350934ba86649
6
+ metadata.gz: 773babee3c280766879e615a654206f1665a3811ac98fe673dcab655ef6e42471335f9cc2605e999eed2aa06a3aa5e6a85ed74fcd4e138b39f97467fc28adef0
7
+ data.tar.gz: 0ab8544aa6011e99256af88dafe207b27509f78b7db906cc41f47192967fc5b24f7fe8d8b352729908083026804ec39f5aec314b27747c2ea222443e092e4276
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.2
4
+
5
+ - Fix issue where `as:` keyword was not handled in JSONAPI relationship formatter.
6
+
3
7
  ## 1.2.1
4
8
 
5
9
  - Update JSONAPI formatter to simplify logic for polymorphic relationships.
@@ -58,9 +58,10 @@ module TypedParams
58
58
  end
59
59
 
60
60
  def self.format_hash_data(data, schema:)
61
- rels = data[:relationships]
62
- attrs = data[:attributes]
63
- res = data.except(
61
+ relationships = data[:relationships]
62
+ attributes = data[:attributes]
63
+
64
+ res = data.except(
64
65
  :attributes,
65
66
  :links,
66
67
  :meta,
@@ -69,18 +70,21 @@ module TypedParams
69
70
  )
70
71
 
71
72
  # Move attributes over to top-level params
72
- attrs&.each do |key, attr|
73
- res[key] = attr
73
+ attributes&.each do |key, attribute|
74
+ res[key] = attribute
74
75
  end
75
76
 
76
77
  # Move relationships over. This will use x_id and x_ids when the
77
78
  # relationship data only contains :type and :id, otherwise it
78
79
  # will use the x_attributes key.
79
- rels&.each do |key, rel|
80
- child = schema.children.fetch(:relationships)
81
- .children.fetch(key)
82
-
83
- case rel
80
+ relationships&.each do |key, relationship|
81
+ child = schema.children.fetch(:relationships).then do |rels|
82
+ rels.children.fetch(key) {
83
+ rels.children.values.find { _1.as == key || _1.alias == key }
84
+ }
85
+ end
86
+
87
+ case relationship
84
88
  # FIXME(ezekg) We need https://bugs.ruby-lang.org/issues/18961 to
85
89
  # clean this up (i.e. remove the if guard).
86
90
  in data: [{ type:, id:, **nil }, *] => linkage if linkage.all? { _1 in type:, id:, **nil }
@@ -96,7 +100,7 @@ module TypedParams
96
100
  else
97
101
  # NOTE(ezekg) Embedded relationships are non-standard as per the
98
102
  # JSONAPI spec, but I don't really care. :)
99
- res[:"#{key}_attributes"] = call(rel, schema: child)
103
+ res[:"#{key}_attributes"] = call(relationship, schema: child)
100
104
  end
101
105
  end
102
106
 
@@ -10,6 +10,7 @@ module TypedParams
10
10
  :source,
11
11
  :type,
12
12
  :key,
13
+ :as,
13
14
  :alias,
14
15
  :if,
15
16
  :unless
@@ -80,6 +81,7 @@ module TypedParams
80
81
  @strict = strict
81
82
  @parent = parent
82
83
  @key = key
84
+ @as = as
83
85
  @alias = binding.local_variable_get(:alias)
84
86
  @optional = optional
85
87
  @coerce = coerce && @type.coercable?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TypedParams
4
- VERSION = '1.2.1'
4
+ VERSION = '1.2.2'
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.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zeke Gabrielse