smart_params 6.0.1 → 6.0.3

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: f5a757ef69761d43ce38da683b79975b5f2a9f712ac79824cd386ea0d1c8b12f
4
- data.tar.gz: a569e347394533b8466d49cf4c4ed9ac3b1df6a3a6997640d8a2a46aeb142541
3
+ metadata.gz: 7370c79a63c141964de25a0888d1103ac3cf0a9f13bdaa8bf07eab31fe933450
4
+ data.tar.gz: d337ebf978437cddc01026ccb97016bc248abe8a63aee2626940bf82a432010b
5
5
  SHA512:
6
- metadata.gz: 8d6e2886fa056a1d5d5f66a2af46eb0e0034d3a0adcb7d2c75d5f54e1663ea261f67da8b3ba0fb7ffd1bfc8c5ee8104f8aaf90315ffaf18bc954cb199be2cad0
7
- data.tar.gz: 6fc0347f0a76bdc4ec4863924a3f29200563dd0f3550216294da9899f7a22fe8c46f508527b3d5fffad515c05377c758fc449ab1d164f75d1395726293679a3a
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.1"
4
+ VERSION = "6.0.3"
5
5
  end
data/lib/smart_params.rb CHANGED
@@ -6,6 +6,8 @@ require "active_support/core_ext/object"
6
6
  require "active_support/core_ext/module"
7
7
 
8
8
  module SmartParams
9
+ require_relative "smart_params/missing_type_annotation_exception"
10
+ require_relative "smart_params/path_already_defined_exception"
9
11
  require_relative "smart_params/invalid_payload_exception"
10
12
  require_relative "smart_params/invalid_property_type_exception"
11
13
  require_relative "smart_params/missing_property_exception"
@@ -37,8 +39,10 @@ module SmartParams
37
39
  case field.map(raw)
38
40
  in :skip
39
41
  [result, failures]
40
- in [:ok, value]
41
- [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]
42
46
  in Dry::Types::Result::Success => success
43
47
  [field.update_in(result, success.input), failures]
44
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.1
4
+ version: 6.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kurtis Rainbolt-Greene