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 +4 -4
- data/lib/smart_params/field.rb +5 -5
- data/lib/smart_params/version.rb +1 -1
- data/lib/smart_params.rb +6 -2
- data/lib/smart_params_spec.rb +20 -17
- 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: 7370c79a63c141964de25a0888d1103ac3cf0a9f13bdaa8bf07eab31fe933450
|
4
|
+
data.tar.gz: d337ebf978437cddc01026ccb97016bc248abe8a63aee2626940bf82a432010b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c4aa150806e1c0b8361838528edf725c316465d8172136acbd68775d7ecb01b8b78f7a65b649471d2e436b2608756accc38a72d693aedc5820ea45b8a0df347
|
7
|
+
data.tar.gz: a1931ae0f5ce052dbb5fc9790adcc92911dc6930e656f7b481159108370227eef32a244c4cbeb42f773e7268958069891e311a8d5824334fca8b5eb96cfdbbdc
|
data/lib/smart_params/field.rb
CHANGED
@@ -29,11 +29,11 @@ module SmartParams
|
|
29
29
|
def update_in(result, value)
|
30
30
|
*body, butt = @path
|
31
31
|
|
32
|
-
|
33
|
-
mapping
|
34
|
-
|
35
|
-
|
36
|
-
|
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)
|
data/lib/smart_params/version.rb
CHANGED
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,
|
41
|
-
[field.update_in(result,
|
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
|
data/lib/smart_params_spec.rb
CHANGED
@@ -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 "
|
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(
|