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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d16aaa23be8e59e9ba013dae058827ae33544285
4
- data.tar.gz: cfc6d13d0827b516eb5e397e7eff867010719a3e
3
+ metadata.gz: 74b5749358f4ebe0ad63c81411946f093dc5c0c3
4
+ data.tar.gz: dfe24997e6c6880860f48ff0fb0d4651bbdd014f
5
5
  SHA512:
6
- metadata.gz: 6dc1d842656ad1f360a8d2fc2667abafbd14fcb7bb412c881e317119958557cd914883bd8b8d5890719c155b051aed811925bf17a5f61d3e6ab3cfedd2d0430e
7
- data.tar.gz: 863949df7cc4bcc2425761eeaa0461ad1e35d279da4c9e6c617df9754c5dbd35c95a655b57282d354ab1760f404a14b7ef1cca32971529bbc993799c1bcb835f
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
- standard_instance = standard_plat.new
19
-
20
- custom_plat.fields.each do |custom_field_name, custom_field|
21
- if custom_field.standard_field.present?
22
- raw_standard_value = get_raw_standard_value(
23
- custom_field,
24
- custom_instance[custom_field_name],
25
- standard_instance
26
- )
27
- raw_standard_value = custom_field.standard_field.cast(raw_standard_value)
28
- standard_instance[custom_field.standard_field.name] = raw_standard_value
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
- [custom_instance, standard_instance].each do |instance|
33
- instance.send(:after_convert, from: custom_instance, to: standard_instance)
34
- end
34
+ [custom_instance, standard_instance].each do |instance|
35
+ instance.send(:after_convert, from: custom_instance, to: standard_instance)
36
+ end
35
37
 
36
- standard_instance
38
+ standard_instance
39
+ end
37
40
  end
38
41
 
39
- def convert_to(custom_plat)
40
- converter = FieldMapper::Standard::Converter.new(convert_to_standard)
41
- converter.convert_to(custom_plat)
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
- raise StandardMismatch if custom_plat.standard_plat != standard_plat
14
-
15
- custom_instance = custom_plat.new
16
-
17
- standard_plat.fields.each do |standard_field_name, standard_field|
18
- custom_fields = custom_plat.find_mapped_fields(standard_field)
19
- custom_fields.each do |custom_field|
20
- raw_custom_value = get_raw_custom_value(
21
- custom_field,
22
- standard_instance[standard_field_name],
23
- custom_instance
24
- )
25
- raw_custom_value = custom_field.cast(raw_custom_value)
26
- custom_instance[custom_field.name] = raw_custom_value
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
- [standard_instance, custom_instance].each do |instance|
31
- instance.send(:after_convert, from: standard_instance, to: custom_instance)
32
- end
33
+ [standard_instance, custom_instance].each do |instance|
34
+ instance.send(:after_convert, from: standard_instance, to: custom_instance)
35
+ end
33
36
 
34
- custom_instance
37
+ custom_instance
38
+ end
35
39
  end
36
40
 
37
41
  protected
@@ -1,3 +1,3 @@
1
1
  module FieldMapper
2
- VERSION = "0.3.13"
2
+ VERSION = "0.3.14"
3
3
  end
@@ -3,7 +3,7 @@ require_relative "plat_example"
3
3
  require_relative "plat_example_alt"
4
4
 
5
5
  module Custom
6
- class ConverterTest < MicroTest::Test
6
+ class ConverterTest < PryTest::Test
7
7
 
8
8
  before do
9
9
  @custom = Custom::PlatExample.new
@@ -1,7 +1,7 @@
1
1
  require_relative "../test_helper"
2
2
 
3
3
  module Custom
4
- class FieldTest < MicroTest::Test
4
+ class FieldTest < PryTest::Test
5
5
 
6
6
  test "constructor requires type" do
7
7
  begin
@@ -2,7 +2,7 @@ require_relative "../test_helper"
2
2
  require_relative "plat_example"
3
3
 
4
4
  module Custom
5
- class PlatTest < MicroTest::Test
5
+ class PlatTest < PryTest::Test
6
6
 
7
7
  before do
8
8
  @class = Custom::PlatExample
@@ -1,7 +1,7 @@
1
1
  require_relative "../test_helper"
2
2
 
3
3
  module Custom
4
- class ValueTest < MicroTest::Test
4
+ class ValueTest < PryTest::Test
5
5
 
6
6
  before do
7
7
  standard_field = FieldMapper::Standard::Field.new(:foo, type: String)
data/test/readme_test.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require_relative "test_helper"
2
2
 
3
- class ReadmeTest < MicroTest::Test
3
+ class ReadmeTest < PryTest::Test
4
4
 
5
5
  test "readme examples" do
6
6
 
@@ -4,7 +4,7 @@ require_relative "../custom/plat_example"
4
4
  require_relative "../custom/plat_example_alt"
5
5
 
6
6
  module Standard
7
- class ConverterTest < MicroTest::Test
7
+ class ConverterTest < PryTest::Test
8
8
 
9
9
  before do
10
10
  @standard = Standard::PlatExample.new
@@ -2,7 +2,7 @@ require_relative "../test_helper"
2
2
  require_relative "plat_example"
3
3
 
4
4
  module Standard
5
- class FieldTest < MicroTest::Test
5
+ class FieldTest < PryTest::Test
6
6
 
7
7
  test "constructor requires type" do
8
8
  begin
@@ -2,7 +2,7 @@ require_relative "../test_helper"
2
2
  require_relative "plat_example"
3
3
 
4
4
  module Standard
5
- class PlatTest < MicroTest::Test
5
+ class PlatTest < PryTest::Test
6
6
 
7
7
  before do
8
8
  @class = Standard::PlatExample
@@ -1,7 +1,7 @@
1
1
  require_relative "../test_helper"
2
2
 
3
3
  module Standard
4
- class ValueTest < MicroTest::Test
4
+ class ValueTest < PryTest::Test
5
5
 
6
6
  test "constructor requires field" do
7
7
  begin
data/test/test_helper.rb CHANGED
@@ -5,7 +5,7 @@ if ENV["CI"]
5
5
  SimpleCov.formatter = Coveralls::SimpleCov::Formatter
6
6
  end
7
7
 
8
- SimpleCov.command_name "micro_test"
8
+ SimpleCov.command_name "pry-test"
9
9
  SimpleCov.start do
10
10
  add_filter "/test/"
11
11
  end
@@ -1,6 +1,6 @@
1
1
  require_relative "../test_helper"
2
2
 
3
- class BooleanTest < MicroTest::Test
3
+ class BooleanTest < PryTest::Test
4
4
  Boolean = FieldMapper::Types::Boolean
5
5
 
6
6
  test "parse nil" do
@@ -1,7 +1,7 @@
1
1
  require_relative "../test_helper"
2
2
  require_relative "../standard/plat_example"
3
3
 
4
- class ListTest < MicroTest::Test
4
+ class ListTest < PryTest::Test
5
5
 
6
6
  test "initialize fails with instance type" do
7
7
  begin
@@ -1,7 +1,7 @@
1
1
  require_relative "../test_helper"
2
2
  require_relative "../standard/plat_example"
3
3
 
4
- class PlatTest < MicroTest::Test
4
+ class PlatTest < PryTest::Test
5
5
 
6
6
  test "initialize fails with instance type" do
7
7
  begin
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.13
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: 2014-11-10 00:00:00.000000000 Z
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: micro_test
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.2.0
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: