yaoc 0.0.13 → 0.0.14
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 +4 -4
 - data/.rubocop.yml +2 -0
 - data/.travis.yml +4 -0
 - data/Gemfile +5 -1
 - data/Guardfile +5 -0
 - data/Rakefile +3 -0
 - data/examples/01_hash_enabled_constructors.rb +8 -8
 - data/examples/02_procs_as_constructors.rb +11 -13
 - data/examples/03_positional_constructors.rb +7 -13
 - data/examples/04_compositions.rb +3 -8
 - data/examples/05_fill_existing_objects.rb +2 -8
 - data/examples/06_lazy_loading.rb +0 -7
 - data/examples/all_examples.rb +2 -2
 - data/lib/yaoc.rb +2 -3
 - data/lib/yaoc/converter_builder.rb +14 -21
 - data/lib/yaoc/helper/struct_hash_constructor.rb +3 -4
 - data/lib/yaoc/helper/to_proc_delegator.rb +4 -6
 - data/lib/yaoc/many_to_one_mapper_chain.rb +11 -13
 - data/lib/yaoc/mapper_registry.rb +3 -4
 - data/lib/yaoc/mapping_base.rb +11 -12
 - data/lib/yaoc/mapping_to_class.rb +7 -9
 - data/lib/yaoc/object_mapper.rb +10 -13
 - data/lib/yaoc/one_to_many_mapper_chain.rb +4 -6
 - data/lib/yaoc/strategies/to_array_mapping.rb +1 -3
 - data/lib/yaoc/strategies/to_hash_mapping.rb +1 -3
 - data/lib/yaoc/transformation_command.rb +27 -8
 - data/lib/yaoc/transformation_deferred_command.rb +3 -5
 - data/lib/yaoc/version.rb +1 -1
 - data/rubocop-todo.yml +96 -0
 - data/spec/acceptance/fill_existing_objects_spec.rb +30 -30
 - data/spec/acceptance/map_multiple_objects_to_one_in_a_chain_spec.rb +15 -15
 - data/spec/acceptance/map_objects_spec.rb +22 -22
 - data/spec/acceptance/map_one_object_to_many_in_a_chain_spec.rb +15 -15
 - data/spec/acceptance/map_to_objects_using_other_converters_spec.rb +53 -55
 - data/spec/acceptance/map_to_objects_with_lazy_loading_spec.rb +17 -17
 - data/spec/acceptance/map_to_objects_with_positional_constructors_spec.rb +19 -19
 - data/spec/integration/lib/yaoc/converter_builder_spec.rb +21 -21
 - data/spec/spec_helper.rb +7 -7
 - data/spec/support/feature.rb +1 -2
 - data/spec/unit/lib/yaoc/converter_builder_spec.rb +42 -44
 - data/spec/unit/lib/yaoc/helper/struct_hash_constructor_spec.rb +15 -15
 - data/spec/unit/lib/yaoc/helper/to_proc_delegator_spec.rb +11 -11
 - data/spec/unit/lib/yaoc/many_to_one_mapper_chain_spec.rb +19 -20
 - data/spec/unit/lib/yaoc/mapper_registry_spec.rb +6 -6
 - data/spec/unit/lib/yaoc/mapping_base_spec.rb +36 -36
 - data/spec/unit/lib/yaoc/mapping_to_class_spec.rb +19 -21
 - data/spec/unit/lib/yaoc/object_mapper_spec.rb +45 -49
 - data/spec/unit/lib/yaoc/one_to_many_mapper_chain_spec.rb +17 -18
 - data/spec/unit/lib/yaoc/strategies/to_array_mapping_spec.rb +23 -24
 - data/spec/unit/lib/yaoc/strategies/to_hash_mapping_spec.rb +25 -25
 - data/spec/unit/lib/yaoc/transformation_command_spec.rb +13 -13
 - data/spec/unit/lib/yaoc/transformation_deferred_command_spec.rb +9 -9
 - data/yaoc.gemspec +1 -0
 - metadata +18 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 414cadb073e1ee5125583448bc11850b421bf2b9
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 67b410e6314bad5c32e77948517e9e169b98a032
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 289e384c84ec5ff6ed0e5f503ad4292071a3612086f2027c4ec1104a52ef06ebc085dd1716be70bc3fed27baf5cc27b4e891b7981453c688c60c7077779c23c6
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 39efb5ded23bcf1208ddd4e54f29f8a8e349d5a2fd29f32b96e09ee832df75056d0a10606664b1a4853fa8cd3bc1cd7dba3be25a5d8f2bab08bedee6adab99b1
         
     | 
    
        data/.rubocop.yml
    ADDED
    
    
    
        data/.travis.yml
    CHANGED
    
    
    
        data/Gemfile
    CHANGED
    
    
    
        data/Guardfile
    CHANGED
    
    
    
        data/Rakefile
    CHANGED
    
    
| 
         @@ -16,19 +16,19 @@ mapper = Yaoc::ObjectMapper.new(User, OldUser).tap do |mapper| 
     | 
|
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         
             
                rule to: :firstname,
         
     | 
| 
       18 
18 
     | 
    
         
             
                     from: :fullname,
         
     | 
| 
       19 
     | 
    
         
            -
                     converter: ->(source, result){ Yaoc::TransformationCommand.fill_result_with_value(result, :firstname, source.fullname.split 
     | 
| 
       20 
     | 
    
         
            -
                     reverse_converter: ->(source, result){ Yaoc::TransformationCommand.fill_result_with_value(result, :fullname,  "#{source.firstname} #{source.lastname}") }
         
     | 
| 
      
 19 
     | 
    
         
            +
                     converter: ->(source, result) { Yaoc::TransformationCommand.fill_result_with_value(result, :firstname, source.fullname.split.first) },
         
     | 
| 
      
 20 
     | 
    
         
            +
                     reverse_converter: ->(source, result) { Yaoc::TransformationCommand.fill_result_with_value(result, :fullname,  "#{source.firstname} #{source.lastname}") }
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
22 
     | 
    
         
             
                rule to: :lastname,
         
     | 
| 
       23 
23 
     | 
    
         
             
                     from: :fullname,
         
     | 
| 
       24 
     | 
    
         
            -
                     converter: ->(source, result){ Yaoc::TransformationCommand.fill_result_with_value(result, :lastname, source.fullname.split 
     | 
| 
       25 
     | 
    
         
            -
                     reverse_converter: ->(source, result){ result }
         
     | 
| 
      
 24 
     | 
    
         
            +
                     converter: ->(source, result) { Yaoc::TransformationCommand.fill_result_with_value(result, :lastname, source.fullname.split.last) },
         
     | 
| 
      
 25 
     | 
    
         
            +
                     reverse_converter: ->(source, result) { result }
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
27 
     | 
    
         
             
                rule to: :id
         
     | 
| 
       28 
28 
     | 
    
         
             
              end
         
     | 
| 
       29 
29 
     | 
    
         
             
            end
         
     | 
| 
       30 
30 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
            old_user = OldUser.new( 
     | 
| 
      
 31 
     | 
    
         
            +
            old_user = OldUser.new(id: 1, fullname: 'myfirst mysecond', r_role: 'admin')
         
     | 
| 
       32 
32 
     | 
    
         
             
            new_user = mapper.load(old_user)
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
34 
     | 
    
         
             
            puts "\n" * 5
         
     | 
| 
         @@ -36,9 +36,9 @@ puts "\n" * 5 
     | 
|
| 
       36 
36 
     | 
    
         
             
            puts old_user
         
     | 
| 
       37 
37 
     | 
    
         
             
            puts new_user
         
     | 
| 
       38 
38 
     | 
    
         | 
| 
       39 
     | 
    
         
            -
            new_user.firstname =  
     | 
| 
       40 
     | 
    
         
            -
            new_user.lastname =  
     | 
| 
      
 39 
     | 
    
         
            +
            new_user.firstname = 'no'
         
     | 
| 
      
 40 
     | 
    
         
            +
            new_user.lastname = 'name'
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
       42 
42 
     | 
    
         
             
            puts mapper.dump(new_user)
         
     | 
| 
       43 
43 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
            puts "\n" * 5
         
     | 
| 
      
 44 
     | 
    
         
            +
            puts "\n" * 5
         
     | 
| 
         @@ -11,21 +11,21 @@ OldUser2 = Struct.new(:id, :fullname, :r_role) 
     | 
|
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
            User2 = Struct.new(:id, :firstname, :lastname, :role)
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
            reverse_source = ->(attrs) 
     | 
| 
      
 14 
     | 
    
         
            +
            reverse_source = ->(attrs)do
         
     | 
| 
       15 
15 
     | 
    
         
             
              OldUser2.new.tap do |old_user|
         
     | 
| 
       16 
16 
     | 
    
         
             
                attrs.each_pair do |key, value|
         
     | 
| 
       17 
17 
     | 
    
         
             
                  old_user.public_send "#{key}=", value
         
     | 
| 
       18 
18 
     | 
    
         
             
                end
         
     | 
| 
       19 
19 
     | 
    
         
             
              end
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
      
 20 
     | 
    
         
            +
            end
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
            source = ->(attrs) 
     | 
| 
      
 22 
     | 
    
         
            +
            source = ->(attrs)do
         
     | 
| 
       23 
23 
     | 
    
         
             
              User2.new.tap do |old_user|
         
     | 
| 
       24 
24 
     | 
    
         
             
                attrs.each_pair do |key, value|
         
     | 
| 
       25 
25 
     | 
    
         
             
                  old_user.public_send "#{key}=", value
         
     | 
| 
       26 
26 
     | 
    
         
             
                end
         
     | 
| 
       27 
27 
     | 
    
         
             
              end
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
      
 28 
     | 
    
         
            +
            end
         
     | 
| 
       29 
29 
     | 
    
         | 
| 
       30 
30 
     | 
    
         
             
            mapper = Yaoc::ObjectMapper.new(source, reverse_source).tap do |mapper|
         
     | 
| 
       31 
31 
     | 
    
         
             
              mapper.add_mapping do
         
     | 
| 
         @@ -34,29 +34,27 @@ mapper = Yaoc::ObjectMapper.new(source, reverse_source).tap do |mapper| 
     | 
|
| 
       34 
34 
     | 
    
         | 
| 
       35 
35 
     | 
    
         
             
                rule to: :firstname,
         
     | 
| 
       36 
36 
     | 
    
         
             
                     from: :fullname,
         
     | 
| 
       37 
     | 
    
         
            -
                     converter: ->(source, result){ Yaoc::TransformationCommand.fill_result_with_value(result, :firstname,  source.fullname.split 
     | 
| 
       38 
     | 
    
         
            -
                     reverse_converter: ->(source, result){ Yaoc::TransformationCommand.fill_result_with_value(result, :fullname, "#{source.firstname} #{source.lastname}") }
         
     | 
| 
      
 37 
     | 
    
         
            +
                     converter: ->(source, result) { Yaoc::TransformationCommand.fill_result_with_value(result, :firstname,  source.fullname.split.first) },
         
     | 
| 
      
 38 
     | 
    
         
            +
                     reverse_converter: ->(source, result) { Yaoc::TransformationCommand.fill_result_with_value(result, :fullname, "#{source.firstname} #{source.lastname}") }
         
     | 
| 
       39 
39 
     | 
    
         | 
| 
       40 
40 
     | 
    
         
             
                rule to: :lastname,
         
     | 
| 
       41 
41 
     | 
    
         
             
                     from: :fullname,
         
     | 
| 
       42 
     | 
    
         
            -
                     converter: ->(source, result){ Yaoc::TransformationCommand.fill_result_with_value(result, :lastname,  source.fullname.split 
     | 
| 
       43 
     | 
    
         
            -
                     reverse_converter: ->(source, result){ result }
         
     | 
| 
      
 42 
     | 
    
         
            +
                     converter: ->(source, result) { Yaoc::TransformationCommand.fill_result_with_value(result, :lastname,  source.fullname.split.last) },
         
     | 
| 
      
 43 
     | 
    
         
            +
                     reverse_converter: ->(source, result) { result }
         
     | 
| 
       44 
44 
     | 
    
         | 
| 
       45 
45 
     | 
    
         
             
                rule to: :id
         
     | 
| 
       46 
46 
     | 
    
         
             
              end
         
     | 
| 
       47 
47 
     | 
    
         
             
            end
         
     | 
| 
       48 
48 
     | 
    
         | 
| 
       49 
     | 
    
         
            -
            old_user2 = OldUser2.new(1,  
     | 
| 
      
 49 
     | 
    
         
            +
            old_user2 = OldUser2.new(1, 'myfirst mysecond',  'admin')
         
     | 
| 
       50 
50 
     | 
    
         
             
            new_user2 = mapper.load(old_user2)
         
     | 
| 
       51 
51 
     | 
    
         | 
| 
       52 
52 
     | 
    
         
             
            puts old_user2
         
     | 
| 
       53 
53 
     | 
    
         
             
            puts new_user2
         
     | 
| 
       54 
54 
     | 
    
         | 
| 
       55 
     | 
    
         
            -
            new_user2.firstname =  
     | 
| 
       56 
     | 
    
         
            -
            new_user2.lastname =  
     | 
| 
      
 55 
     | 
    
         
            +
            new_user2.firstname = 'no'
         
     | 
| 
      
 56 
     | 
    
         
            +
            new_user2.lastname = 'name'
         
     | 
| 
       57 
57 
     | 
    
         | 
| 
       58 
58 
     | 
    
         
             
            puts mapper.dump(new_user2)
         
     | 
| 
       59 
59 
     | 
    
         | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
60 
     | 
    
         
             
            puts "\n" * 5
         
     | 
| 
         @@ -10,16 +10,15 @@ puts "\n" * 5 
     | 
|
| 
       10 
10 
     | 
    
         
             
            OldUser3 = Struct.new(:id, :fullname, :r_role)
         
     | 
| 
       11 
11 
     | 
    
         
             
            User3 = Struct.new(:id, :firstname, :lastname, :role)
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
13 
     | 
    
         
             
            converter = Yaoc::TransformationCommand.create(to: 1,
         
     | 
| 
       15 
14 
     | 
    
         
             
                                                           from: :fullname,
         
     | 
| 
       16 
15 
     | 
    
         
             
                                                           deferred: false,
         
     | 
| 
       17 
     | 
    
         
            -
                                                           fetcher_proc: ->(source, fetcher, from){source.fullname.split 
     | 
| 
      
 16 
     | 
    
         
            +
                                                           fetcher_proc: ->(source, fetcher, from) {source.fullname.split.first })
         
     | 
| 
       18 
17 
     | 
    
         | 
| 
       19 
18 
     | 
    
         
             
            reverse_converter = Yaoc::TransformationCommand.create(to: 1,
         
     | 
| 
       20 
19 
     | 
    
         
             
                                                                   from: :first_and_lastname,
         
     | 
| 
       21 
20 
     | 
    
         
             
                                                                   deferred: false,
         
     | 
| 
       22 
     | 
    
         
            -
                                                                   fetcher_proc: ->(source, fetcher, from){ "#{source.firstname} #{source.lastname}"} 
     | 
| 
      
 21 
     | 
    
         
            +
                                                                   fetcher_proc: ->(source, fetcher, from) { "#{source.firstname} #{source.lastname}" })
         
     | 
| 
       23 
22 
     | 
    
         | 
| 
       24 
23 
     | 
    
         
             
            mapper = Yaoc::ObjectMapper.new(User3, OldUser3).tap do |mapper|
         
     | 
| 
       25 
24 
     | 
    
         
             
              mapper.add_mapping do
         
     | 
| 
         @@ -40,8 +39,8 @@ mapper = Yaoc::ObjectMapper.new(User3, OldUser3).tap do |mapper| 
     | 
|
| 
       40 
39 
     | 
    
         
             
                rule to: 2,
         
     | 
| 
       41 
40 
     | 
    
         
             
                     from: :fullname,
         
     | 
| 
       42 
41 
     | 
    
         | 
| 
       43 
     | 
    
         
            -
                     converter: ->(source, result){ result[2]  = source.fullname.split 
     | 
| 
       44 
     | 
    
         
            -
                     reverse_converter: ->(source, result){ result }
         
     | 
| 
      
 42 
     | 
    
         
            +
                     converter: ->(source, result) { result[2]  = source.fullname.split.last },
         
     | 
| 
      
 43 
     | 
    
         
            +
                     reverse_converter: ->(source, result) { result }
         
     | 
| 
       45 
44 
     | 
    
         | 
| 
       46 
45 
     | 
    
         
             
                rule to: 3, from: :r_role,
         
     | 
| 
       47 
46 
     | 
    
         
             
                     reverse_to: 2, reverse_from: :role
         
     | 
| 
         @@ -49,20 +48,15 @@ mapper = Yaoc::ObjectMapper.new(User3, OldUser3).tap do |mapper| 
     | 
|
| 
       49 
48 
     | 
    
         
             
              end
         
     | 
| 
       50 
49 
     | 
    
         
             
            end
         
     | 
| 
       51 
50 
     | 
    
         | 
| 
       52 
     | 
    
         
            -
            old_user3 = OldUser3.new(1,  
     | 
| 
      
 51 
     | 
    
         
            +
            old_user3 = OldUser3.new(1, 'myfirst mysecond',  'admin')
         
     | 
| 
       53 
52 
     | 
    
         
             
            new_user3 = mapper.load(old_user3)
         
     | 
| 
       54 
53 
     | 
    
         | 
| 
       55 
54 
     | 
    
         
             
            puts old_user3
         
     | 
| 
       56 
55 
     | 
    
         
             
            puts new_user3
         
     | 
| 
       57 
56 
     | 
    
         | 
| 
       58 
     | 
    
         
            -
            new_user3.firstname =  
     | 
| 
       59 
     | 
    
         
            -
            new_user3.lastname =  
     | 
| 
      
 57 
     | 
    
         
            +
            new_user3.firstname = 'no'
         
     | 
| 
      
 58 
     | 
    
         
            +
            new_user3.lastname = 'name'
         
     | 
| 
       60 
59 
     | 
    
         | 
| 
       61 
60 
     | 
    
         
             
            puts mapper.dump(new_user3)
         
     | 
| 
       62 
61 
     | 
    
         | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
62 
     | 
    
         
             
            puts "\n" * 5
         
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
             
     | 
    
        data/examples/04_compositions.rb
    CHANGED
    
    | 
         @@ -5,20 +5,16 @@ require 'yaoc' 
     | 
|
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            include Yaoc::Helper
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
8 
     | 
    
         
             
            puts "\n" * 5
         
     | 
| 
       10 
9 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
10 
     | 
    
         
             
            User4 = StructHE(:id, :firstname, :lastname, :roles)
         
     | 
| 
       13 
11 
     | 
    
         | 
| 
       14 
12 
     | 
    
         
             
            OldUser4 = StructHE(:o_id, :o_firstname, :o_lastname, :o_roles)
         
     | 
| 
       15 
13 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
14 
     | 
    
         
             
            Role = StructHE(:id, :name)
         
     | 
| 
       18 
15 
     | 
    
         | 
| 
       19 
16 
     | 
    
         
             
            OldRole = StructHE(:o_id, :o_name)
         
     | 
| 
       20 
17 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
18 
     | 
    
         
             
            Yaoc::ObjectMapper.new(Role, OldRole).tap do |mapper|
         
     | 
| 
       23 
19 
     | 
    
         
             
              mapper.add_mapping do
         
     | 
| 
       24 
20 
     | 
    
         
             
                register_as :role_mapper
         
     | 
| 
         @@ -45,11 +41,10 @@ user_mapper = Yaoc::ObjectMapper.new(User4, OldUser4).tap do |mapper| 
     | 
|
| 
       45 
41 
     | 
    
         
             
              end
         
     | 
| 
       46 
42 
     | 
    
         
             
            end
         
     | 
| 
       47 
43 
     | 
    
         | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
44 
     | 
    
         
             
            old_user4 = OldUser4.new(o_id: 1,
         
     | 
| 
       50 
     | 
    
         
            -
                                     o_firstname:  
     | 
| 
       51 
     | 
    
         
            -
                                     o_lastname: 
     | 
| 
       52 
     | 
    
         
            -
                                     o_roles: [OldRole.new(o_id: 1, o_name:  
     | 
| 
      
 45 
     | 
    
         
            +
                                     o_firstname: 'firstname',
         
     | 
| 
      
 46 
     | 
    
         
            +
                                     o_lastname:'lastname',
         
     | 
| 
      
 47 
     | 
    
         
            +
                                     o_roles: [OldRole.new(o_id: 1, o_name: 'admin'), OldRole.new(o_id: 2, o_name: 'guest')])
         
     | 
| 
       53 
48 
     | 
    
         
             
            new_user4 = user_mapper.load(old_user4)
         
     | 
| 
       54 
49 
     | 
    
         | 
| 
       55 
50 
     | 
    
         
             
            puts old_user4
         
     | 
| 
         @@ -13,7 +13,6 @@ RoleThing = StructHE(:id, :role) 
     | 
|
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
            User5 = StructHE(:id, :name,  :role)
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
16 
     | 
    
         
             
            user_mapper = Yaoc::ObjectMapper.new(User5, OldUser5).tap do |mapper|
         
     | 
| 
       18 
17 
     | 
    
         
             
              mapper.add_mapping do
         
     | 
| 
       19 
18 
     | 
    
         
             
                fetcher :public_send
         
     | 
| 
         @@ -28,8 +27,8 @@ role_mapper = Yaoc::ObjectMapper.new(User5, RoleThing).tap do |mapper| 
     | 
|
| 
       28 
27 
     | 
    
         
             
              end
         
     | 
| 
       29 
28 
     | 
    
         
             
            end
         
     | 
| 
       30 
29 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
            old_role = RoleThing.new(id: 1, role:  
     | 
| 
       32 
     | 
    
         
            -
            old_user5 = OldUser5.new(id: 1, name:  
     | 
| 
      
 30 
     | 
    
         
            +
            old_role = RoleThing.new(id: 1, role: 'my_role')
         
     | 
| 
      
 31 
     | 
    
         
            +
            old_user5 = OldUser5.new(id: 1, name: 'my fullname')
         
     | 
| 
       33 
32 
     | 
    
         
             
            new_user5 = user_mapper.load(old_user5)
         
     | 
| 
       34 
33 
     | 
    
         | 
| 
       35 
34 
     | 
    
         
             
            role_mapper.load(old_role, new_user5)
         
     | 
| 
         @@ -46,13 +45,8 @@ mapper_chain = Yaoc::ManyToOneMapperChain.new(user_mapper, role_mapper) 
     | 
|
| 
       46 
45 
     | 
    
         | 
| 
       47 
46 
     | 
    
         
             
            new_user5 = mapper_chain.load_all([old_user5, old_role])
         
     | 
| 
       48 
47 
     | 
    
         | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
48 
     | 
    
         
             
            puts old_user5
         
     | 
| 
       51 
49 
     | 
    
         
             
            puts old_role
         
     | 
| 
       52 
50 
     | 
    
         
             
            puts new_user5
         
     | 
| 
       53 
51 
     | 
    
         | 
| 
       54 
52 
     | 
    
         
             
            puts "\n" * 5
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
    
        data/examples/06_lazy_loading.rb
    CHANGED
    
    | 
         @@ -7,7 +7,6 @@ include Yaoc::Helper 
     | 
|
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
            puts "\n" * 5
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
10 
     | 
    
         
             
            OldUser6 = StructHE(:id) do
         
     | 
| 
       12 
11 
     | 
    
         | 
| 
       13 
12 
     | 
    
         
             
              def names=(new_names)
         
     | 
| 
         @@ -23,7 +22,6 @@ OldUser6 = StructHE(:id) do 
     | 
|
| 
       23 
22 
     | 
    
         
             
            end
         
     | 
| 
       24 
23 
     | 
    
         
             
            User6 = StructHE(:id, :names)
         
     | 
| 
       25 
24 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
25 
     | 
    
         
             
            user_mapper = Yaoc::ObjectMapper.new(User6, OldUser6).tap do |mapper|
         
     | 
| 
       28 
26 
     | 
    
         
             
              mapper.add_mapping do
         
     | 
| 
       29 
27 
     | 
    
         
             
                fetcher :public_send
         
     | 
| 
         @@ -39,9 +37,4 @@ puts new_user6.id.inspect 
     | 
|
| 
       39 
37 
     | 
    
         
             
            puts new_user6.names.inspect
         
     | 
| 
       40 
38 
     | 
    
         
             
            puts new_user6
         
     | 
| 
       41 
39 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
40 
     | 
    
         
             
            puts "\n" * 5
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
    
        data/examples/all_examples.rb
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            Dir[File.join(File.expand_path(__dir__ 
     | 
| 
      
 1 
     | 
    
         
            +
            Dir[File.join(File.expand_path(__dir__), '*.rb')].sort.each do |f|
         
     | 
| 
       2 
2 
     | 
    
         
             
              unless f =~ /#{__FILE__}$/
         
     | 
| 
       3 
3 
     | 
    
         
             
                command = %W(ruby #{f})
         
     | 
| 
       4 
4 
     | 
    
         
             
                puts "executing #{command.join(" ")}"
         
     | 
| 
       5 
5 
     | 
    
         
             
                system *command
         
     | 
| 
       6 
6 
     | 
    
         
             
              end
         
     | 
| 
       7 
     | 
    
         
            -
            end
         
     | 
| 
      
 7 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/yaoc.rb
    CHANGED
    
    | 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require  
     | 
| 
      
 1 
     | 
    
         
            +
            require 'yaoc/version'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            require 'scoped_storage'
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
         @@ -11,7 +11,7 @@ require 'yaoc/transformation_command' 
     | 
|
| 
       11 
11 
     | 
    
         
             
            require 'yaoc/transformation_deferred_command'
         
     | 
| 
       12 
12 
     | 
    
         
             
            require 'yaoc/mapping_to_class'
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
            Dir[File.join(File.expand_path(__dir__ 
     | 
| 
      
 14 
     | 
    
         
            +
            Dir[File.join(File.expand_path(__dir__), 'yaoc/strategies/*.rb')].each { |f| require f }
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
            require 'yaoc/converter_builder'
         
     | 
| 
       17 
17 
     | 
    
         
             
            require 'yaoc/object_mapper'
         
     | 
| 
         @@ -19,5 +19,4 @@ require 'yaoc/many_to_one_mapper_chain' 
     | 
|
| 
       19 
19 
     | 
    
         
             
            require 'yaoc/one_to_many_mapper_chain'
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
21 
     | 
    
         
             
            module Yaoc
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
22 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,5 +1,4 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Yaoc
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
2 
     | 
    
         
             
              class NormalizedParameters
         
     | 
| 
       4 
3 
     | 
    
         
             
                attr_accessor :to_s, :from_s, :converter_s, :lazy_loading_s
         
     | 
| 
       5 
4 
     | 
    
         | 
| 
         @@ -12,7 +11,7 @@ module Yaoc 
     | 
|
| 
       12 
11 
     | 
    
         
             
                  object_converter_s = Array(object_converter)
         
     | 
| 
       13 
12 
     | 
    
         
             
                  is_collection_s = Array(is_collection)
         
     | 
| 
       14 
13 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
                   
     | 
| 
      
 14 
     | 
    
         
            +
                  to_s.each_with_index do |to, index|
         
     | 
| 
       16 
15 
     | 
    
         
             
                    from_s[index] ||= to
         
     | 
| 
       17 
16 
     | 
    
         
             
                    lazy_loading_s[index] ||= false
         
     | 
| 
       18 
17 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -24,20 +23,18 @@ module Yaoc 
     | 
|
| 
       24 
23 
     | 
    
         
             
                                                           !!is_collection_s[index],
         
     | 
| 
       25 
24 
     | 
    
         
             
                                                           !!lazy_loading_s[index])
         
     | 
| 
       26 
25 
     | 
    
         
             
                  end
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
26 
     | 
    
         
             
                end
         
     | 
| 
       29 
27 
     | 
    
         | 
| 
       30 
28 
     | 
    
         
             
                def each
         
     | 
| 
       31 
29 
     | 
    
         
             
                  return to_enum(__callee__) unless block_given?
         
     | 
| 
       32 
30 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
                   
     | 
| 
      
 31 
     | 
    
         
            +
                  to_s.each_with_index do |to, index|
         
     | 
| 
       34 
32 
     | 
    
         
             
                    yield to, from_s[index] , converter_s[index], lazy_loading_s[index]
         
     | 
| 
       35 
33 
     | 
    
         
             
                  end
         
     | 
| 
       36 
34 
     | 
    
         
             
                end
         
     | 
| 
       37 
35 
     | 
    
         | 
| 
       38 
36 
     | 
    
         
             
                def converter_to_proc(to, from, converter, is_collection, deferred)
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
                  get_value_with = ->(source, fetcher, from){
         
     | 
| 
      
 37 
     | 
    
         
            +
                  get_value_with = ->(source, fetcher, from)do
         
     | 
| 
       41 
38 
     | 
    
         
             
                    object_to_convert = source.public_send(fetcher, from)
         
     | 
| 
       42 
39 
     | 
    
         | 
| 
       43 
40 
     | 
    
         
             
                    if is_collection
         
     | 
| 
         @@ -46,11 +43,10 @@ module Yaoc 
     | 
|
| 
       46 
43 
     | 
    
         
             
                      converter_as_proc = converter.to_proc
         
     | 
| 
       47 
44 
     | 
    
         
             
                      converter_as_proc.call(object_to_convert)
         
     | 
| 
       48 
45 
     | 
    
         
             
                    end
         
     | 
| 
       49 
     | 
    
         
            -
                   
     | 
| 
      
 46 
     | 
    
         
            +
                  end
         
     | 
| 
       50 
47 
     | 
    
         | 
| 
       51 
48 
     | 
    
         
             
                  TransformationCommand.create(to: to, from: from, deferred: deferred, fetcher_proc: get_value_with)
         
     | 
| 
       52 
49 
     | 
    
         
             
                end
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
50 
     | 
    
         
             
              end
         
     | 
| 
       55 
51 
     | 
    
         | 
| 
       56 
52 
     | 
    
         
             
              module BuilderDSLMethods
         
     | 
| 
         @@ -63,7 +59,7 @@ module Yaoc 
     | 
|
| 
       63 
59 
     | 
    
         
             
                  self.all_commands_applied = false
         
     | 
| 
       64 
60 
     | 
    
         | 
| 
       65 
61 
     | 
    
         
             
                  NormalizedParameters.new(to, from, converter, object_converter, is_collection, lazy_loading).each do |to, from, converter, lazy_loading|
         
     | 
| 
       66 
     | 
    
         
            -
                    build_commands.push  ->{ converter_class.map(to: to, from: from , converter: converter, lazy_loading: lazy_loading) }
         
     | 
| 
      
 62 
     | 
    
         
            +
                    build_commands.push  -> { converter_class.map(to: to, from: from , converter: converter, lazy_loading: lazy_loading) }
         
     | 
| 
       67 
63 
     | 
    
         
             
                  end
         
     | 
| 
       68 
64 
     | 
    
         
             
                end
         
     | 
| 
       69 
65 
     | 
    
         | 
| 
         @@ -84,18 +80,17 @@ module Yaoc 
     | 
|
| 
       84 
80 
     | 
    
         
             
                end
         
     | 
| 
       85 
81 
     | 
    
         | 
| 
       86 
82 
     | 
    
         
             
                def noop
         
     | 
| 
       87 
     | 
    
         
            -
                  ->(_, result){ result }
         
     | 
| 
      
 83 
     | 
    
         
            +
                  ->(_, result) { result }
         
     | 
| 
       88 
84 
     | 
    
         
             
                end
         
     | 
| 
       89 
85 
     | 
    
         
             
              end
         
     | 
| 
       90 
86 
     | 
    
         | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
87 
     | 
    
         
             
              class ConverterBuilder
         
     | 
| 
       93 
88 
     | 
    
         
             
                include BuilderDSLMethods
         
     | 
| 
       94 
89 
     | 
    
         | 
| 
       95 
90 
     | 
    
         
             
                attr_accessor  :build_commands, :command_order,
         
     | 
| 
       96 
91 
     | 
    
         
             
                               :strategy, :all_commands_applied
         
     | 
| 
       97 
92 
     | 
    
         | 
| 
       98 
     | 
    
         
            -
                def initialize(command_order 
     | 
| 
      
 93 
     | 
    
         
            +
                def initialize(command_order = :recorded_order, fetcher = :fetch)
         
     | 
| 
       99 
94 
     | 
    
         
             
                  self.build_commands = []
         
     | 
| 
       100 
95 
     | 
    
         
             
                  self.command_order = command_order
         
     | 
| 
       101 
96 
     | 
    
         
             
                  self.fetcher = fetcher
         
     | 
| 
         @@ -110,13 +105,13 @@ module Yaoc 
     | 
|
| 
       110 
105 
     | 
    
         
             
                  build_commands_ordered.each &:call
         
     | 
| 
       111 
106 
     | 
    
         
             
                end
         
     | 
| 
       112 
107 
     | 
    
         | 
| 
       113 
     | 
    
         
            -
                def converter(fetch_able, target_source=nil)
         
     | 
| 
       114 
     | 
    
         
            -
                   
     | 
| 
       115 
     | 
    
         
            -
                  converter_class.new(fetch_able, fetcher, target_source || ->(attrs){ attrs})
         
     | 
| 
      
 108 
     | 
    
         
            +
                def converter(fetch_able, target_source = nil)
         
     | 
| 
      
 109 
     | 
    
         
            +
                  fail 'BuildCommandsNotExecuted' unless self.all_commands_applied?
         
     | 
| 
      
 110 
     | 
    
         
            +
                  converter_class.new(fetch_able, fetcher, target_source || ->(attrs) { attrs })
         
     | 
| 
       116 
111 
     | 
    
         
             
                end
         
     | 
| 
       117 
112 
     | 
    
         | 
| 
       118 
113 
     | 
    
         
             
                def fetcher=(new_fetcher)
         
     | 
| 
       119 
     | 
    
         
            -
                  @fetcher= new_fetcher
         
     | 
| 
      
 114 
     | 
    
         
            +
                  @fetcher = new_fetcher
         
     | 
| 
       120 
115 
     | 
    
         
             
                end
         
     | 
| 
       121 
116 
     | 
    
         | 
| 
       122 
117 
     | 
    
         
             
                protected
         
     | 
| 
         @@ -136,9 +131,9 @@ module Yaoc 
     | 
|
| 
       136 
131 
     | 
    
         | 
| 
       137 
132 
     | 
    
         
             
                def sym_as_module_name(sym)
         
     | 
| 
       138 
133 
     | 
    
         
             
                  sym.to_s
         
     | 
| 
       139 
     | 
    
         
            -
                     .split( 
     | 
| 
      
 134 
     | 
    
         
            +
                     .split('_')
         
     | 
| 
       140 
135 
     | 
    
         
             
                     .map(&:capitalize)
         
     | 
| 
       141 
     | 
    
         
            -
                     .join 
     | 
| 
      
 136 
     | 
    
         
            +
                     .join
         
     | 
| 
       142 
137 
     | 
    
         
             
                     .to_sym
         
     | 
| 
       143 
138 
     | 
    
         
             
                end
         
     | 
| 
       144 
139 
     | 
    
         | 
| 
         @@ -153,7 +148,5 @@ module Yaoc 
     | 
|
| 
       153 
148 
     | 
    
         
             
                def reset_converters!
         
     | 
| 
       154 
149 
     | 
    
         
             
                  @converter_class = nil
         
     | 
| 
       155 
150 
     | 
    
         
             
                end
         
     | 
| 
       156 
     | 
    
         
            -
             
     | 
| 
       157 
151 
     | 
    
         
             
              end
         
     | 
| 
       158 
     | 
    
         
            -
             
     | 
| 
       159 
     | 
    
         
            -
            end
         
     | 
| 
      
 152 
     | 
    
         
            +
            end
         
     |