field_mapper 0.3.13 → 0.3.14
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/converter.rb +27 -20
- data/lib/field_mapper/standard/converter.rb +24 -20
- data/lib/field_mapper/version.rb +1 -1
- data/test/custom/converter_test.rb +1 -1
- data/test/custom/field_test.rb +1 -1
- data/test/custom/plat_test.rb +1 -1
- data/test/custom/value_test.rb +1 -1
- data/test/readme_test.rb +1 -1
- data/test/standard/converter_test.rb +1 -1
- data/test/standard/field_test.rb +1 -1
- data/test/standard/plat_test.rb +1 -1
- data/test/standard/value_test.rb +1 -1
- data/test/test_helper.rb +1 -1
- data/test/types/boolean_test.rb +1 -1
- data/test/types/list_test.rb +1 -1
- data/test/types/plat_test.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74b5749358f4ebe0ad63c81411946f093dc5c0c3
|
4
|
+
data.tar.gz: dfe24997e6c6880860f48ff0fb0d4651bbdd014f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecb56a0caf40ec5eebec6bc33f4ced0d4b6930fb6964756421f917511e2b7041c45cf6732fa9f0827f1b6e7db557b8e8600f0ef0462f02737568eac41a6aa852
|
7
|
+
data.tar.gz: fa219b6fc1c4c3e56eab3f7212c0cc407205a2541c47110fcf5ea58366dfbd29b0df90ee9639c522a932b073dd71dafbd885533539c81bcd5e70aa152e067cf6
|
@@ -14,31 +14,38 @@ module FieldMapper
|
|
14
14
|
@standard_plat = custom_plat.standard_plat
|
15
15
|
end
|
16
16
|
|
17
|
-
def convert_to_standard
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
17
|
+
def convert_to_standard(memoize: true)
|
18
|
+
@converterd_to_standard = nil unless memoize
|
19
|
+
@converterd_to_standard ||= begin
|
20
|
+
standard_instance = standard_plat.new
|
21
|
+
|
22
|
+
custom_plat.fields.each do |custom_field_name, custom_field|
|
23
|
+
if custom_field.standard_field.present?
|
24
|
+
raw_standard_value = get_raw_standard_value(
|
25
|
+
custom_field,
|
26
|
+
custom_instance[custom_field_name],
|
27
|
+
standard_instance
|
28
|
+
)
|
29
|
+
raw_standard_value = custom_field.standard_field.cast(raw_standard_value)
|
30
|
+
standard_instance[custom_field.standard_field.name] = raw_standard_value
|
31
|
+
end
|
29
32
|
end
|
30
|
-
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
[custom_instance, standard_instance].each do |instance|
|
35
|
+
instance.send(:after_convert, from: custom_instance, to: standard_instance)
|
36
|
+
end
|
35
37
|
|
36
|
-
|
38
|
+
standard_instance
|
39
|
+
end
|
37
40
|
end
|
38
41
|
|
39
|
-
def convert_to(custom_plat)
|
40
|
-
|
41
|
-
|
42
|
+
def convert_to(custom_plat, memoize: true)
|
43
|
+
@converted_to_custom ||= {}
|
44
|
+
@converted_to_custom[custom_plat] = nil unless memoize
|
45
|
+
@converted_to_custom[custom_plat] ||= begin
|
46
|
+
converter = FieldMapper::Standard::Converter.new(convert_to_standard)
|
47
|
+
converter.convert_to(custom_plat)
|
48
|
+
end
|
42
49
|
end
|
43
50
|
|
44
51
|
protected
|
@@ -9,29 +9,33 @@ module FieldMapper
|
|
9
9
|
@standard_instance = standard_instance
|
10
10
|
end
|
11
11
|
|
12
|
-
def convert_to(custom_plat)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
12
|
+
def convert_to(custom_plat, memoize: true)
|
13
|
+
@converted_to_custom ||= {}
|
14
|
+
@converted_to_custom[custom_plat] = nil unless memoize
|
15
|
+
@converted_to_custom[custom_plat] ||= begin
|
16
|
+
raise StandardMismatch if custom_plat.standard_plat != standard_plat
|
17
|
+
|
18
|
+
custom_instance = custom_plat.new
|
19
|
+
|
20
|
+
standard_plat.fields.each do |standard_field_name, standard_field|
|
21
|
+
custom_fields = custom_plat.find_mapped_fields(standard_field)
|
22
|
+
custom_fields.each do |custom_field|
|
23
|
+
raw_custom_value = get_raw_custom_value(
|
24
|
+
custom_field,
|
25
|
+
standard_instance[standard_field_name],
|
26
|
+
custom_instance
|
27
|
+
)
|
28
|
+
raw_custom_value = custom_field.cast(raw_custom_value)
|
29
|
+
custom_instance[custom_field.name] = raw_custom_value
|
30
|
+
end
|
27
31
|
end
|
28
|
-
end
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
+
[standard_instance, custom_instance].each do |instance|
|
34
|
+
instance.send(:after_convert, from: standard_instance, to: custom_instance)
|
35
|
+
end
|
33
36
|
|
34
|
-
|
37
|
+
custom_instance
|
38
|
+
end
|
35
39
|
end
|
36
40
|
|
37
41
|
protected
|
data/lib/field_mapper/version.rb
CHANGED
data/test/custom/field_test.rb
CHANGED
data/test/custom/plat_test.rb
CHANGED
data/test/custom/value_test.rb
CHANGED
data/test/readme_test.rb
CHANGED
data/test/standard/field_test.rb
CHANGED
data/test/standard/plat_test.rb
CHANGED
data/test/standard/value_test.rb
CHANGED
data/test/test_helper.rb
CHANGED
data/test/types/boolean_test.rb
CHANGED
data/test/types/list_test.rb
CHANGED
data/test/types/plat_test.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: field_mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Hopkins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: pry-test
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
@@ -196,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
196
196
|
version: '0'
|
197
197
|
requirements: []
|
198
198
|
rubyforge_project:
|
199
|
-
rubygems_version: 2.
|
199
|
+
rubygems_version: 2.4.5
|
200
200
|
signing_key:
|
201
201
|
specification_version: 4
|
202
202
|
summary: Data mapping & transformation
|
@@ -217,3 +217,4 @@ test_files:
|
|
217
217
|
- test/types/boolean_test.rb
|
218
218
|
- test/types/list_test.rb
|
219
219
|
- test/types/plat_test.rb
|
220
|
+
has_rdoc:
|