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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/.travis.yml +4 -0
  4. data/Gemfile +5 -1
  5. data/Guardfile +5 -0
  6. data/Rakefile +3 -0
  7. data/examples/01_hash_enabled_constructors.rb +8 -8
  8. data/examples/02_procs_as_constructors.rb +11 -13
  9. data/examples/03_positional_constructors.rb +7 -13
  10. data/examples/04_compositions.rb +3 -8
  11. data/examples/05_fill_existing_objects.rb +2 -8
  12. data/examples/06_lazy_loading.rb +0 -7
  13. data/examples/all_examples.rb +2 -2
  14. data/lib/yaoc.rb +2 -3
  15. data/lib/yaoc/converter_builder.rb +14 -21
  16. data/lib/yaoc/helper/struct_hash_constructor.rb +3 -4
  17. data/lib/yaoc/helper/to_proc_delegator.rb +4 -6
  18. data/lib/yaoc/many_to_one_mapper_chain.rb +11 -13
  19. data/lib/yaoc/mapper_registry.rb +3 -4
  20. data/lib/yaoc/mapping_base.rb +11 -12
  21. data/lib/yaoc/mapping_to_class.rb +7 -9
  22. data/lib/yaoc/object_mapper.rb +10 -13
  23. data/lib/yaoc/one_to_many_mapper_chain.rb +4 -6
  24. data/lib/yaoc/strategies/to_array_mapping.rb +1 -3
  25. data/lib/yaoc/strategies/to_hash_mapping.rb +1 -3
  26. data/lib/yaoc/transformation_command.rb +27 -8
  27. data/lib/yaoc/transformation_deferred_command.rb +3 -5
  28. data/lib/yaoc/version.rb +1 -1
  29. data/rubocop-todo.yml +96 -0
  30. data/spec/acceptance/fill_existing_objects_spec.rb +30 -30
  31. data/spec/acceptance/map_multiple_objects_to_one_in_a_chain_spec.rb +15 -15
  32. data/spec/acceptance/map_objects_spec.rb +22 -22
  33. data/spec/acceptance/map_one_object_to_many_in_a_chain_spec.rb +15 -15
  34. data/spec/acceptance/map_to_objects_using_other_converters_spec.rb +53 -55
  35. data/spec/acceptance/map_to_objects_with_lazy_loading_spec.rb +17 -17
  36. data/spec/acceptance/map_to_objects_with_positional_constructors_spec.rb +19 -19
  37. data/spec/integration/lib/yaoc/converter_builder_spec.rb +21 -21
  38. data/spec/spec_helper.rb +7 -7
  39. data/spec/support/feature.rb +1 -2
  40. data/spec/unit/lib/yaoc/converter_builder_spec.rb +42 -44
  41. data/spec/unit/lib/yaoc/helper/struct_hash_constructor_spec.rb +15 -15
  42. data/spec/unit/lib/yaoc/helper/to_proc_delegator_spec.rb +11 -11
  43. data/spec/unit/lib/yaoc/many_to_one_mapper_chain_spec.rb +19 -20
  44. data/spec/unit/lib/yaoc/mapper_registry_spec.rb +6 -6
  45. data/spec/unit/lib/yaoc/mapping_base_spec.rb +36 -36
  46. data/spec/unit/lib/yaoc/mapping_to_class_spec.rb +19 -21
  47. data/spec/unit/lib/yaoc/object_mapper_spec.rb +45 -49
  48. data/spec/unit/lib/yaoc/one_to_many_mapper_chain_spec.rb +17 -18
  49. data/spec/unit/lib/yaoc/strategies/to_array_mapping_spec.rb +23 -24
  50. data/spec/unit/lib/yaoc/strategies/to_hash_mapping_spec.rb +25 -25
  51. data/spec/unit/lib/yaoc/transformation_command_spec.rb +13 -13
  52. data/spec/unit/lib/yaoc/transformation_deferred_command_spec.rb +9 -9
  53. data/yaoc.gemspec +1 -0
  54. metadata +18 -2
@@ -1,10 +1,9 @@
1
1
  module Yaoc
2
2
  class TransformationDeferredCommand < TransformationCommand
3
-
4
3
  def value(time_saved_to_convert)
5
- proc = ->{
4
+ proc = ->do
6
5
  value_fetcher_proc.call(time_saved_to_convert, fetcher, from)
7
- }
6
+ end
8
7
 
9
8
  TransformationDeferredCommand.deferrer_strategy(proc)
10
9
  end
@@ -12,6 +11,5 @@ module Yaoc
12
11
  def self.deferrer_strategy(proc)
13
12
  Yaoc::Helper::ToProcDelegator.new(proc)
14
13
  end
15
-
16
14
  end
17
- end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module Yaoc
2
- VERSION = "0.0.13"
2
+ VERSION = '0.0.14'
3
3
  end
@@ -0,0 +1,96 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2014-04-14 15:02:25 +0200 using RuboCop version 0.18.1.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offences are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offence count: 6
9
+ # Cop supports --auto-correct.
10
+ Alias:
11
+ Enabled: false
12
+
13
+ # Offence count: 6
14
+ AmbiguousOperator:
15
+ Enabled: false
16
+
17
+ # Offence count: 28
18
+ Documentation:
19
+ Enabled: false
20
+
21
+ # Offence count: 1
22
+ FavorSprintf:
23
+ Enabled: false
24
+
25
+ # Offence count: 12
26
+ Lambda:
27
+ Enabled: false
28
+
29
+ # Offence count: 105
30
+ LineLength:
31
+ Max: 184
32
+
33
+ # Offence count: 4
34
+ # Configuration parameters: CountComments.
35
+ MethodLength:
36
+ Max: 28
37
+
38
+ # Offence count: 2
39
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
40
+ MethodName:
41
+ Enabled: false
42
+
43
+ # Offence count: 1
44
+ MultilineBlockChain:
45
+ Enabled: false
46
+
47
+ # Offence count: 1
48
+ OneLineConditional:
49
+ Enabled: false
50
+
51
+ # Offence count: 3
52
+ # Configuration parameters: CountKeywordArgs.
53
+ ParameterLists:
54
+ Max: 11
55
+
56
+ # Offence count: 1
57
+ ParenthesesAsGroupedExpression:
58
+ Enabled: false
59
+
60
+ # Offence count: 17
61
+ ShadowingOuterLocalVariable:
62
+ Enabled: false
63
+
64
+ # Offence count: 1
65
+ # Cop supports --auto-correct.
66
+ SpaceAfterColon:
67
+ Enabled: false
68
+
69
+ # Offence count: 4
70
+ # Cop supports --auto-correct.
71
+ SpaceAfterComma:
72
+ Enabled: false
73
+
74
+ # Offence count: 1
75
+ # Cop supports --auto-correct.
76
+ SpaceAfterNot:
77
+ Enabled: false
78
+
79
+ # Offence count: 9
80
+ # Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
81
+ TrailingComma:
82
+ Enabled: false
83
+
84
+ # Offence count: 6
85
+ # Configuration parameters: ExactNameMatch, AllowPredicates, Whitelist.
86
+ TrivialAccessors:
87
+ Enabled: false
88
+
89
+ # Offence count: 3
90
+ UnlessElse:
91
+ Enabled: false
92
+
93
+ # Offence count: 29
94
+ # Cop supports --auto-correct.
95
+ WordArray:
96
+ MinSize: 4
@@ -1,20 +1,20 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
- feature "Fill existing objects", %q{
3
+ feature 'Fill existing objects', %q{
4
4
  In order to use this lib with pre created objects
5
5
  as a lib user
6
6
  I want to be able to fill exiting objects instead of create a new one
7
7
  } do
8
8
 
9
- given(:new_user_class){
9
+ given(:new_user_class)do
10
10
  Yaoc::Helper::StructHE(:id, :firstname, :lastname, :roles)
11
- }
11
+ end
12
12
 
13
- given(:old_user_class){
13
+ given(:old_user_class)do
14
14
  Yaoc::Helper::StructHE(:o_id, :o_firstname, :o_lastname)
15
- }
15
+ end
16
16
 
17
- given(:user_converter){
17
+ given(:user_converter)do
18
18
 
19
19
  Yaoc::ObjectMapper.new(new_user_class, old_user_class).tap do |mapper|
20
20
  mapper.add_mapping do
@@ -25,55 +25,55 @@ feature "Fill existing objects", %q{
25
25
 
26
26
  end
27
27
  end
28
- }
28
+ end
29
29
 
30
- given(:expected_new_user) {
30
+ given(:expected_new_user) do
31
31
  new_user_class.new(
32
- id: "user_1",
33
- firstname: "o firstname",
34
- lastname: "o lastname",
35
- roles: "admin, ruth, guest"
32
+ id: 'user_1',
33
+ firstname: 'o firstname',
34
+ lastname: 'o lastname',
35
+ roles: 'admin, ruth, guest'
36
36
  )
37
- }
37
+ end
38
38
 
39
- given(:existing_user){
39
+ given(:existing_user)do
40
40
  new_user_class.new(
41
41
  id: nil,
42
42
  firstname: nil,
43
43
  lastname: nil,
44
- roles: "admin, ruth, guest"
44
+ roles: 'admin, ruth, guest'
45
45
  )
46
- }
46
+ end
47
47
 
48
- given(:existing_old_user){
48
+ given(:existing_old_user)do
49
49
  old_user_class.new(
50
- o_id: "existing_user_2",
51
- o_firstname: "o existing_firstname",
52
- o_lastname: "o existing_lastname"
50
+ o_id: 'existing_user_2',
51
+ o_firstname: 'o existing_firstname',
52
+ o_lastname: 'o existing_lastname'
53
53
  )
54
- }
54
+ end
55
55
 
56
- given(:old_user) {
56
+ given(:old_user) do
57
57
  old_user_class.new(
58
- o_id: "user_1",
59
- o_firstname: "o firstname",
60
- o_lastname: "o lastname"
58
+ o_id: 'user_1',
59
+ o_firstname: 'o firstname',
60
+ o_lastname: 'o lastname'
61
61
 
62
62
  )
63
- }
63
+ end
64
64
 
65
- scenario "creates an result object from an input_object" do
65
+ scenario 'creates an result object from an input_object' do
66
66
  conversion_result = user_converter.load(old_user, existing_user)
67
67
 
68
68
  expect(conversion_result.object_id).to eq existing_user.object_id
69
69
  expect(conversion_result).to eq expected_new_user
70
70
  end
71
71
 
72
- scenario "dumps an result object as result object" do
72
+ scenario 'dumps an result object as result object' do
73
73
  conversion_result = user_converter.dump(expected_new_user, existing_old_user)
74
74
 
75
75
  expect(conversion_result.object_id).to eq existing_old_user.object_id
76
76
  expect(conversion_result).to eq old_user
77
77
  end
78
78
 
79
- end
79
+ end
@@ -6,11 +6,11 @@ feature 'Map multiple objects to one', %q{
6
6
  I want to be able to chain converters and input objects
7
7
  } do
8
8
 
9
- given(:mapper_chain){
9
+ given(:mapper_chain)do
10
10
  Yaoc::ManyToOneMapperChain.new(first_mapper, second_mapper)
11
- }
11
+ end
12
12
 
13
- given!(:first_mapper){
13
+ given!(:first_mapper)do
14
14
  Yaoc::ObjectMapper.new(new_user_class, old_user_class).tap do |mapper|
15
15
  mapper.add_mapping do
16
16
  register_as :first_mapper
@@ -18,9 +18,9 @@ feature 'Map multiple objects to one', %q{
18
18
  rule to: :id
19
19
  end
20
20
  end
21
- }
21
+ end
22
22
 
23
- given!(:second_mapper){
23
+ given!(:second_mapper)do
24
24
  Yaoc::ObjectMapper.new(new_user_class, old_user_class).tap do |mapper|
25
25
  mapper.add_mapping do
26
26
  register_as :second_mapper
@@ -28,29 +28,29 @@ feature 'Map multiple objects to one', %q{
28
28
  rule to: :names
29
29
  end
30
30
  end
31
- }
31
+ end
32
32
 
33
- given(:new_user_class){
33
+ given(:new_user_class)do
34
34
  Yaoc::Helper::StructHE(:id, :names)
35
- }
35
+ end
36
36
 
37
- given(:old_user_class){
37
+ given(:old_user_class)do
38
38
  Yaoc::Helper::StructHE(:id, :names)
39
- }
39
+ end
40
40
 
41
- given(:existing_old_user){
41
+ given(:existing_old_user)do
42
42
  old_user_class.new(
43
43
  id: 'existing_user_2',
44
44
  names: ['first_name', 'second_name']
45
45
  )
46
- }
46
+ end
47
47
 
48
- given(:existing_user){
48
+ given(:existing_user)do
49
49
  new_user_class.new(
50
50
  id: 'existing_user_2',
51
51
  names: ['first_name', 'second_name']
52
52
  )
53
- }
53
+ end
54
54
 
55
55
  scenario 'loads an result object from multiple input object' do
56
56
  converted_user = mapper_chain.load_all([existing_old_user, existing_old_user])
@@ -75,4 +75,4 @@ feature 'Map multiple objects to one', %q{
75
75
  expect(converted_user.names).to eq ['first_name', 'second_name']
76
76
  end
77
77
 
78
- end
78
+ end
@@ -1,54 +1,54 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
- feature "Map objects", %q{
3
+ feature 'Map objects', %q{
4
4
  In order to map object
5
5
  as a lib user
6
6
  I want to map object from an input object to an output object and reverse
7
7
  } do
8
8
 
9
- given(:mapper){
9
+ given(:mapper)do
10
10
  Yaoc::ObjectMapper.new(load_result_object_class, dump_result_object_class).tap do |mapper|
11
11
  mapper.add_mapping do
12
12
  fetcher :public_send
13
13
  reverse_fetcher :public_send
14
14
  rule to: :name,
15
- converter: ->(source, result){ Yaoc::TransformationCommand.fill_result_with_value(result, :name, "#{source[:name]} Hello World") },
16
- reverse_converter: ->(source, result){ Yaoc::TransformationCommand.fill_result_with_value(result, :name, source.name) }
15
+ converter: ->(source, result) { Yaoc::TransformationCommand.fill_result_with_value(result, :name, "#{source[:name]} Hello World") },
16
+ reverse_converter: ->(source, result) { Yaoc::TransformationCommand.fill_result_with_value(result, :name, source.name) }
17
17
  rule to: :role, from: :fullrolename
18
18
  rule to: :id
19
19
  rule to: [:foo, :bar]
20
20
  end
21
21
  end
22
- }
22
+ end
23
23
 
24
- given(:load_result_object_class) {
24
+ given(:load_result_object_class) do
25
25
  Yaoc::Helper::StructHE(:id, :name, :role, :foo, :bar)
26
- }
26
+ end
27
27
 
28
- given(:dump_result_object_class) {
28
+ given(:dump_result_object_class) do
29
29
  Yaoc::Helper::StructHE(:id, :name, :fullrolename, :foo, :bar)
30
- }
30
+ end
31
31
 
32
- given(:input_object){
32
+ given(:input_object)do
33
33
  dump_result_object
34
- }
34
+ end
35
35
 
36
- given(:load_result_object){
37
- load_result_object_class.new({id: 1, name: "paul", role: "admin", foo: "some thing", bar: "some other thing"})
38
- }
36
+ given(:load_result_object)do
37
+ load_result_object_class.new(id: 1, name: 'paul', role: 'admin', foo: 'some thing', bar: 'some other thing')
38
+ end
39
39
 
40
- given(:dump_result_object){
41
- dump_result_object_class.new({id: 1, name: "paul", fullrolename: "admin", foo: "some thing", bar: "some other thing"})
42
- }
40
+ given(:dump_result_object)do
41
+ dump_result_object_class.new(id: 1, name: 'paul', fullrolename: 'admin', foo: 'some thing', bar: 'some other thing')
42
+ end
43
43
 
44
- scenario "creates an result object from an input_object" do
45
- load_result_object.name += " Hello World"
44
+ scenario 'creates an result object from an input_object' do
45
+ load_result_object.name += ' Hello World'
46
46
 
47
47
  expect(mapper.load(input_object)).to eq load_result_object
48
48
  end
49
49
 
50
- scenario "dumps an result object as result object" do
50
+ scenario 'dumps an result object as result object' do
51
51
  expect(mapper.dump(load_result_object)).to eq dump_result_object
52
52
  end
53
53
 
54
- end
54
+ end
@@ -6,11 +6,11 @@ feature 'Map multiple one object to many', %q{
6
6
  I want to be able to chain converters and get multiple objects out of one
7
7
  } do
8
8
 
9
- given(:mapper_chain){
9
+ given(:mapper_chain)do
10
10
  Yaoc::OneToManyMapperChain.new(first_mapper, second_mapper)
11
- }
11
+ end
12
12
 
13
- given!(:first_mapper){
13
+ given!(:first_mapper)do
14
14
  Yaoc::ObjectMapper.new(new_user_class, old_user_class).tap do |mapper|
15
15
  mapper.add_mapping do
16
16
  register_as :first_mapper
@@ -18,9 +18,9 @@ feature 'Map multiple one object to many', %q{
18
18
  rule to: :id
19
19
  end
20
20
  end
21
- }
21
+ end
22
22
 
23
- given!(:second_mapper){
23
+ given!(:second_mapper)do
24
24
  Yaoc::ObjectMapper.new(new_user_class, old_user_class).tap do |mapper|
25
25
  mapper.add_mapping do
26
26
  register_as :second_mapper
@@ -28,29 +28,29 @@ feature 'Map multiple one object to many', %q{
28
28
  rule to: :names
29
29
  end
30
30
  end
31
- }
31
+ end
32
32
 
33
- given(:new_user_class){
33
+ given(:new_user_class)do
34
34
  Yaoc::Helper::StructHE(:id, :names)
35
- }
35
+ end
36
36
 
37
- given(:old_user_class){
37
+ given(:old_user_class)do
38
38
  Yaoc::Helper::StructHE(:id, :names)
39
- }
39
+ end
40
40
 
41
- given(:existing_old_user){
41
+ given(:existing_old_user)do
42
42
  old_user_class.new(
43
43
  id: 'existing_user_2',
44
44
  names: ['first_name', 'second_name']
45
45
  )
46
- }
46
+ end
47
47
 
48
- given(:existing_user){
48
+ given(:existing_user)do
49
49
  new_user_class.new(
50
50
  id: 'existing_user_2',
51
51
  names: ['first_name', 'second_name']
52
52
  )
53
- }
53
+ end
54
54
 
55
55
  scenario 'loads multiple result object from one input object' do
56
56
  converted_users = mapper_chain.load_all(existing_old_user)
@@ -75,4 +75,4 @@ feature 'Map multiple one object to many', %q{
75
75
  expect(converted_users[1].names).to eq ['first_name', 'second_name']
76
76
  end
77
77
 
78
- end
78
+ end