smart_params 6.0.2 → 6.0.3

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: a5ead1f80985549897380d25e83f63f5d144bd06c55a5f390f3b985a463e7c5a
4
- data.tar.gz: 76b95dc4979d190fb74d98fb341806f126ccce4f53c686b845bb5e90906e7c52
3
+ metadata.gz: 7370c79a63c141964de25a0888d1103ac3cf0a9f13bdaa8bf07eab31fe933450
4
+ data.tar.gz: d337ebf978437cddc01026ccb97016bc248abe8a63aee2626940bf82a432010b
5
5
  SHA512:
6
- metadata.gz: 4b0b5dd7fa36594d448335c13cfe8fb6800b499199e48f31c465e2b2057aeac68132c06a0388a15ea3cbf3f3254afb73668e6eb0f17d68b7957e3d3c98cef6ec
7
- data.tar.gz: 66b24fa6d243a8ad46b35a58c2a28b64efc55bd4308e2ec26ece51011dd44f97f1e3f1f02a69a238a3b6ade4361786146ac30d123454854c3c5caca4f2021c8f
6
+ metadata.gz: 1c4aa150806e1c0b8361838528edf725c316465d8172136acbd68775d7ecb01b8b78f7a65b649471d2e436b2608756accc38a72d693aedc5820ea45b8a0df347
7
+ data.tar.gz: a1931ae0f5ce052dbb5fc9790adcc92911dc6930e656f7b481159108370227eef32a244c4cbeb42f773e7268958069891e311a8d5824334fca8b5eb96cfdbbdc
@@ -29,11 +29,11 @@ module SmartParams
29
29
  def update_in(result, value)
30
30
  *body, butt = @path
31
31
 
32
- body.reduce(result) do |mapping, key|
33
- mapping[key]
34
- end.store(butt, value)
35
-
36
- result
32
+ result.dup.tap do |tree|
33
+ body.reduce(tree) do |mapping, key|
34
+ mapping[key]
35
+ end.store(butt, value)
36
+ end
37
37
  end
38
38
 
39
39
  private def dig_until(keychain, raw)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SmartParams
4
- VERSION = "6.0.2"
4
+ VERSION = "6.0.3"
5
5
  end
data/lib/smart_params.rb CHANGED
@@ -39,8 +39,10 @@ module SmartParams
39
39
  case field.map(raw)
40
40
  in :skip
41
41
  [result, failures]
42
- in [:ok, value]
43
- [field.update_in(result, value), failures]
42
+ in [:ok, nil]
43
+ [field.update_in(result, nil), failures]
44
+ in [:ok, _value]
45
+ [field.update_in(result, {}), failures]
44
46
  in Dry::Types::Result::Success => success
45
47
  [field.update_in(result, success.input), failures]
46
48
  in Dry::Types::Result::Failure => failure
@@ -155,22 +155,6 @@ RSpec.describe SmartParams do
155
155
  )
156
156
  )
157
157
  end
158
-
159
- it "has a chain path data.type" do
160
- expect(subject[:data][:type]).to eq("accounts")
161
- end
162
-
163
- it "has a chain path data.attributes.email" do
164
- expect(subject[:data][:attributes][:email]).to eq("kurtis@example.com")
165
- end
166
-
167
- it "has a chain path data.attributes.password" do
168
- expect(subject[:data][:attributes][:password]).to be_a(String)
169
- end
170
-
171
- it "has a chain path meta.jsonapi_version" do
172
- expect(subject[:meta][:jsonapi_version]).to eq("1.0")
173
- end
174
158
  end
175
159
 
176
160
  context "with extra params" do
@@ -187,7 +171,26 @@ RSpec.describe SmartParams do
187
171
  }
188
172
  end
189
173
 
190
- it "returns as native data types" do
174
+ it "excludes keys not defined" do
175
+ expect(
176
+ subject
177
+ ).to match(
178
+ {
179
+ data: hash_excluding(
180
+ {
181
+ x: "x",
182
+ attributes: hash_including(
183
+ {
184
+ y: "y"
185
+ }
186
+ )
187
+ }
188
+ )
189
+ }
190
+ )
191
+ end
192
+
193
+ it "includes the keys defined" do
191
194
  expect(
192
195
  subject
193
196
  ).to match(
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_params
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.2
4
+ version: 6.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kurtis Rainbolt-Greene