field_mapper 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/field_mapper/custom/plat.rb +19 -2
- data/lib/field_mapper/version.rb +1 -1
- data/test/custom/plat_test.rb +25 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e260db5eb6e48de6cf05f251eb6db4bcb049305
|
4
|
+
data.tar.gz: 1dd1bdf10e815648b9ab03afbf0213f1b2381dbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c685cf81a507b7ee54cb35d391eedd39042da85592272e85285e6a828f1393217e525a2754da9306aa88427a65ee2713a52df0c9683e28cd0c73dd3f60689b9
|
7
|
+
data.tar.gz: 10f1785248c97b3737ce4ecdb177200ed0ea9e808862c99ba061af072dcc02acbc4a3c40e4b6735a5dd746de842bcbdcc1b40269c48e8f8757de379a32e84355
|
@@ -61,13 +61,30 @@ module FieldMapper
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
# TODO: update to work recursively
|
65
64
|
def standard_keys_to_custom_keys(standard_keyed_params)
|
66
65
|
standard_keyed_params.reduce({}) do |memo, standard_param|
|
67
66
|
key = standard_param.first
|
68
67
|
value = standard_param.last
|
69
68
|
field = fields_by_standard_name[key.to_sym]
|
70
|
-
|
69
|
+
|
70
|
+
if !field.nil?
|
71
|
+
case field.type.name
|
72
|
+
when "FieldMapper::Types::Plat" then
|
73
|
+
if value.is_a?(Hash)
|
74
|
+
value = field.type.type.standard_keys_to_custom_keys(value)
|
75
|
+
end
|
76
|
+
when "FieldMapper::Types::List" then
|
77
|
+
if field.type.type.ancestors.include?(Plat)
|
78
|
+
if value.is_a?(Array)
|
79
|
+
value = value.compact.map do |val|
|
80
|
+
field.type.type.standard_keys_to_custom_keys(val)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
memo[field.name] = value
|
86
|
+
end
|
87
|
+
|
71
88
|
memo
|
72
89
|
end
|
73
90
|
end
|
data/lib/field_mapper/version.rb
CHANGED
data/test/custom/plat_test.rb
CHANGED
@@ -24,13 +24,36 @@ module Custom
|
|
24
24
|
end
|
25
25
|
|
26
26
|
test "standard_keys_to_custom_keys" do
|
27
|
-
standard_keyed_params = { score: "A" }
|
27
|
+
standard_keyed_params = { score: "A" }
|
28
28
|
custom_params = Custom::PlatExample.standard_keys_to_custom_keys(standard_keyed_params)
|
29
29
|
assert custom_params[:rating] == "A"
|
30
30
|
end
|
31
31
|
|
32
|
+
test "standard_keys_to_custom_keys recursive" do
|
33
|
+
standard_keyed_params = {
|
34
|
+
score: "A",
|
35
|
+
parent: { score: "B" },
|
36
|
+
children: [
|
37
|
+
{ score: "A" },
|
38
|
+
{ score: "B" },
|
39
|
+
{ score: "C" }
|
40
|
+
]
|
41
|
+
}
|
42
|
+
|
43
|
+
custom_params = Custom::PlatExample.standard_keys_to_custom_keys(standard_keyed_params)
|
44
|
+
assert custom_params == {
|
45
|
+
rating: "A",
|
46
|
+
parent_plat: { rating: "B" },
|
47
|
+
child_plats: [
|
48
|
+
{ rating: "A" },
|
49
|
+
{ rating: "B" },
|
50
|
+
{ rating: "C"}
|
51
|
+
]
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
32
55
|
test "new_from_standard_keyed_params" do
|
33
|
-
standard_keyed_params = { score: "A" }
|
56
|
+
standard_keyed_params = { score: "A" }
|
34
57
|
instance = Custom::PlatExample.new_from_standard_keyed_params(standard_keyed_params)
|
35
58
|
assert instance[:rating] == "A"
|
36
59
|
end
|