field_mapper 0.3.7 → 0.3.8

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
  SHA1:
3
- metadata.gz: 5787388dd0340f6e40fa4fe6687b899ab4c40b65
4
- data.tar.gz: bc1e3bac64aaadf91c5def90224ce26bab25d829
3
+ metadata.gz: 4e260db5eb6e48de6cf05f251eb6db4bcb049305
4
+ data.tar.gz: 1dd1bdf10e815648b9ab03afbf0213f1b2381dbe
5
5
  SHA512:
6
- metadata.gz: a1d18f909bcf83a82190b6faf515e2a4f1c86ea79d6d9e18757ee3cf80bd0dbcb46d379950b1f1cad58a496e5d796f8bfb8df8659f0b4294ba23455da717a7b3
7
- data.tar.gz: c3c17f2f5807b1c4fbc45e8a3744d40791e398f85cad5aba9ae09d28272878ac7955744ed74b397af8c8edaecf7c2f4083e0e4e570e538e40f8dce5a82842255
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
- memo[field.name] = value unless field.nil?
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
@@ -1,3 +1,3 @@
1
1
  module FieldMapper
2
- VERSION = "0.3.7"
2
+ VERSION = "0.3.8"
3
3
  end
@@ -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" } # note that "A" is a custom value
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" } # note that "A" is a custom value
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: field_mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins