yaoc 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
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,21 +1,20 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
- feature "Map objects reusing other existing converters", %q{
3
+ feature 'Map objects reusing other existing converters', %q{
4
4
  In order to map objects with other converters
5
5
  as a lib user
6
6
  I want to map object from an input object to an output object and reverse with a given converter
7
7
  } do
8
8
 
9
-
10
- given(:new_role_class){
9
+ given(:new_role_class)do
11
10
  Yaoc::Helper::StructHE(:id, :name)
12
- }
11
+ end
13
12
 
14
- given(:old_role_class){
13
+ given(:old_role_class)do
15
14
  Yaoc::Helper::StructHE(:o_id, :o_name)
16
- }
15
+ end
17
16
 
18
- given(:role_converter){
17
+ given(:role_converter)do
19
18
  Yaoc::ObjectMapper.new(new_role_class, old_role_class).tap do |mapper|
20
19
  mapper.add_mapping do
21
20
  fetcher :public_send
@@ -25,17 +24,17 @@ feature "Map objects reusing other existing converters", %q{
25
24
 
26
25
  end
27
26
  end
28
- }
27
+ end
29
28
 
30
- given(:new_user_class){
29
+ given(:new_user_class)do
31
30
  Yaoc::Helper::StructHE(:id, :firstname, :lastname, :roles)
32
- }
31
+ end
33
32
 
34
- given(:old_user_class){
33
+ given(:old_user_class)do
35
34
  Yaoc::Helper::StructHE(:o_id, :o_firstname, :o_lastname, :o_roles)
36
- }
35
+ end
37
36
 
38
- given(:user_converter){
37
+ given(:user_converter)do
39
38
  other_converter = role_converter
40
39
  is_col = is_collection
41
40
 
@@ -53,82 +52,81 @@ feature "Map objects reusing other existing converters", %q{
53
52
  is_collection: is_col
54
53
  end
55
54
  end
56
- }
57
-
55
+ end
58
56
 
59
- context "composition is a collection" do
60
- given(:is_collection){
57
+ context 'composition is a collection' do
58
+ given(:is_collection)do
61
59
  true
62
- }
60
+ end
63
61
 
64
- given(:old_user) {
62
+ given(:old_user) do
65
63
  old_user_class.new(
66
- o_id: "user_1",
67
- o_firstname: "o firstname",
68
- o_lastname: "o lastname",
64
+ o_id: 'user_1',
65
+ o_firstname: 'o firstname',
66
+ o_lastname: 'o lastname',
69
67
  o_roles: [
70
- old_role_class.new(o_id: "role_1", o_name: "admin"),
71
- old_role_class.new(o_id: "role_2", o_name: "ruth"),
72
- old_role_class.new(o_id: "role_3", o_name: "guest"),
68
+ old_role_class.new(o_id: 'role_1', o_name: 'admin'),
69
+ old_role_class.new(o_id: 'role_2', o_name: 'ruth'),
70
+ old_role_class.new(o_id: 'role_3', o_name: 'guest'),
73
71
  ]
74
72
  )
75
- }
73
+ end
76
74
 
77
- given(:expected_new_user) {
75
+ given(:expected_new_user) do
78
76
  new_user_class.new(
79
- id: "user_1",
80
- firstname: "o firstname",
81
- lastname: "o lastname",
77
+ id: 'user_1',
78
+ firstname: 'o firstname',
79
+ lastname: 'o lastname',
82
80
  roles: [
83
- new_role_class.new(id: "role_1", name: "admin"),
84
- new_role_class.new(id: "role_2", name: "ruth"),
85
- new_role_class.new(id: "role_3", name: "guest"),
81
+ new_role_class.new(id: 'role_1', name: 'admin'),
82
+ new_role_class.new(id: 'role_2', name: 'ruth'),
83
+ new_role_class.new(id: 'role_3', name: 'guest'),
86
84
  ]
87
85
  )
88
- }
86
+ end
89
87
 
90
- scenario "creates a new user from the old one" do
88
+ scenario 'creates a new user from the old one' do
91
89
  expect(user_converter.load(old_user)).to eq expected_new_user
92
90
  end
93
91
 
94
- scenario "dumps an result object as result object" do
92
+ scenario 'dumps an result object as result object' do
95
93
  expect(user_converter.dump(expected_new_user)).to eq old_user
96
94
  end
97
95
 
98
96
  end
99
97
 
100
- context "composition is a single value" do
101
- given(:is_collection){
98
+ context 'composition is a single value' do
99
+ given(:is_collection)do
102
100
  false
103
- }
101
+ end
104
102
 
105
- given(:old_user) {
103
+ given(:old_user) do
106
104
  old_user_class.new(
107
- o_id: "user_1",
108
- o_firstname: "o firstname",
109
- o_lastname: "o lastname",
110
- o_roles: old_role_class.new(o_id: "role_1", o_name: "admin, ruth, guest")
105
+ o_id: 'user_1',
106
+ o_firstname: 'o firstname',
107
+ o_lastname: 'o lastname',
108
+ o_roles: old_role_class.new(o_id: 'role_1', o_name: 'admin, ruth, guest')
111
109
 
112
110
  )
113
- }
111
+ end
114
112
 
115
- given(:expected_new_user) {
113
+ given(:expected_new_user) do
116
114
  new_user_class.new(
117
- id: "user_1",
118
- firstname: "o firstname",
119
- lastname: "o lastname",
120
- roles: new_role_class.new(id: "role_1", name: "admin, ruth, guest")
115
+ id: 'user_1',
116
+ firstname: 'o firstname',
117
+ lastname: 'o lastname',
118
+ roles: new_role_class.new(id: 'role_1', name: 'admin, ruth, guest')
121
119
  )
122
- }
120
+ end
123
121
 
124
- scenario "creates a new user from the old one" do
122
+ scenario 'creates a new user from the old one' do
125
123
  expect(user_converter.load(old_user)).to eq expected_new_user
126
124
  end
127
125
 
128
- scenario "dumps an result object as result object" do
126
+ scenario 'dumps an result object as result object' do
129
127
  expect(user_converter.dump(expected_new_user)).to eq old_user
130
128
  end
131
129
 
132
130
  end
133
131
 
134
- end
132
+ end
@@ -1,12 +1,12 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
- feature "Map objects to classes with lazy loading", %q{
3
+ feature 'Map objects to classes with lazy loading', %q{
4
4
  In order to defer object mapping
5
5
  as a lib user
6
6
  I want to map object from an input object to an output object with lazy loading support
7
7
  } do
8
8
 
9
- given(:mapper){
9
+ given(:mapper)do
10
10
  Yaoc::ObjectMapper.new(new_user_class, old_user_class).tap do |mapper|
11
11
  mapper.add_mapping do
12
12
  fetcher :public_send
@@ -14,46 +14,46 @@ feature "Map objects to classes with lazy loading", %q{
14
14
  lazy_loading: [false, true]
15
15
  end
16
16
  end
17
- }
17
+ end
18
18
 
19
- given(:new_user_class){
19
+ given(:new_user_class)do
20
20
  Yaoc::Helper::StructHE(:id, :names)
21
- }
21
+ end
22
22
 
23
- given(:old_user_class){
23
+ given(:old_user_class)do
24
24
  Yaoc::Helper::StructHE(:id, :names)
25
- }
25
+ end
26
26
 
27
- given(:existing_old_user){
27
+ given(:existing_old_user)do
28
28
  old_user_class.new(
29
29
  id: 'existing_user_2',
30
30
  names: ['first_name', 'second_name']
31
31
  )
32
- }
32
+ end
33
33
 
34
- given(:existing_user){
34
+ given(:existing_user)do
35
35
  new_user_class.new(
36
36
  id: 'existing_user_2',
37
37
  names: ['first_name', 'second_name']
38
38
  )
39
- }
39
+ end
40
40
 
41
- scenario "creates an result object from an input_object deferred" do
41
+ scenario 'creates an result object from an input_object deferred' do
42
42
  converted_user = mapper.load(existing_old_user)
43
- new_names = ["new_name1", "new_name2"]
43
+ new_names = ['new_name1', 'new_name2']
44
44
 
45
45
  existing_old_user.names = new_names # show defer through changes after loading an object
46
46
 
47
47
  expect(converted_user.names).to eq new_names
48
48
  end
49
49
 
50
- scenario "dumps an result object as source object defered" do
50
+ scenario 'dumps an result object as source object defered' do
51
51
  converted_user = mapper.dump(existing_user)
52
- new_names = ["new_name1", "new_name2"]
52
+ new_names = ['new_name1', 'new_name2']
53
53
 
54
54
  existing_user.names = new_names # show defer through changes after loading an object
55
55
 
56
56
  expect(converted_user.names).to eq new_names
57
57
  end
58
58
 
59
- end
59
+ end
@@ -1,12 +1,12 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
- feature "Map objects to classes with positional constructors", %q{
3
+ feature 'Map objects to classes with positional constructors', %q{
4
4
  In order to map objects with positional constructors
5
5
  as a lib user
6
6
  I want to map object from an input object to an output object and reverse with a given mapping strategy
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
@@ -21,38 +21,38 @@ feature "Map objects to classes with positional constructors", %q{
21
21
  reverse_from: :name
22
22
  end
23
23
  end
24
- }
24
+ end
25
25
 
26
- given(:load_result_object_class) {
26
+ given(:load_result_object_class) do
27
27
  Struct.new(:id, :name) do
28
28
  include Equalizer.new(:id, :name)
29
29
  end
30
- }
30
+ end
31
31
 
32
- given(:dump_result_object_class) {
32
+ given(:dump_result_object_class) do
33
33
  Yaoc::Helper::StructH(:id, :name) do
34
34
  include Equalizer.new(:id, :name)
35
35
  end
36
- }
36
+ end
37
37
 
38
- given(:input_object){
38
+ given(:input_object)do
39
39
  dump_result_object
40
- }
40
+ end
41
41
 
42
- given(:load_result_object){
43
- load_result_object_class.new(1,"paul")
44
- }
42
+ given(:load_result_object)do
43
+ load_result_object_class.new(1,'paul')
44
+ end
45
45
 
46
- given(:dump_result_object){
47
- dump_result_object_class.new({id: 1, name: "paul"})
48
- }
46
+ given(:dump_result_object)do
47
+ dump_result_object_class.new(id: 1, name: 'paul')
48
+ end
49
49
 
50
- scenario "creates an result object from an input_object" do
50
+ scenario 'creates an result object from an input_object' do
51
51
  expect(mapper.load(input_object)).to eq load_result_object
52
52
  end
53
53
 
54
- scenario "dumps an result object as result object" do
54
+ scenario 'dumps an result object as result object' do
55
55
  expect(mapper.dump(load_result_object)).to eq dump_result_object
56
56
  end
57
57
 
58
- end
58
+ end
@@ -1,11 +1,11 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Yaoc::ConverterBuilder do
4
- subject{
4
+ subject do
5
5
  ot = other_converter
6
6
  is_col = is_collection
7
7
 
8
- Yaoc::ConverterBuilder.new().tap{|converter|
8
+ Yaoc::ConverterBuilder.new.tap do|converter|
9
9
  converter.add_mapping do
10
10
  fetch_with :[]
11
11
  rule to: :id,
@@ -13,16 +13,16 @@ describe Yaoc::ConverterBuilder do
13
13
  is_collection: is_col,
14
14
  object_converter: ot
15
15
  end
16
- }
16
+ end
17
17
 
18
- }
18
+ end
19
19
 
20
- let(:other_converter){
21
- Class.new() do
20
+ let(:other_converter)do
21
+ Class.new do
22
22
  def to_proc
23
- @proc ||= ->(index, *args){
23
+ @proc ||= ->(index, *args)do
24
24
  [nil, nil, :my_result_1, nil, :my_result_2][index]
25
- }
25
+ end
26
26
  end
27
27
 
28
28
  def to_a
@@ -30,29 +30,29 @@ describe Yaoc::ConverterBuilder do
30
30
  end
31
31
 
32
32
  end.new
33
- }
33
+ end
34
34
 
35
- let(:is_collection){
35
+ let(:is_collection)do
36
36
  false
37
- }
37
+ end
38
38
 
39
- describe "#converter_to_proc" do
39
+ describe '#converter_to_proc' do
40
40
 
41
- it "creates a converter proc" do
41
+ it 'creates a converter proc' do
42
42
  expect(other_converter.to_proc).to receive(:call).with(2).and_return(:my_result)
43
- expect(subject.converter(nil, nil).map_0000_name_to_id({:name => 2},{})).to eq(id: :my_result)
43
+ expect(subject.converter(nil, nil).map_0000_name_to_id({ name: 2 },{})).to eq(id: :my_result)
44
44
  end
45
45
 
46
- context "value to convert is a collection" do
47
- let(:is_collection){
46
+ context 'value to convert is a collection' do
47
+ let(:is_collection)do
48
48
  true
49
- }
49
+ end
50
50
 
51
- it "creates a converter proc for collections" do
52
- expect(subject.converter(nil, nil).map_0000_name_to_id({:name => [2, 4]},{})).to eq(id: [:my_result_1, :my_result_2])
51
+ it 'creates a converter proc for collections' do
52
+ expect(subject.converter(nil, nil).map_0000_name_to_id({ name: [2, 4] },{})).to eq(id: [:my_result_1, :my_result_2])
53
53
  end
54
54
 
55
55
  end
56
56
  end
57
57
 
58
- end
58
+ end
@@ -2,26 +2,26 @@ require 'bundler/setup'
2
2
  Bundler.require(:development)
3
3
 
4
4
  require 'coveralls'
5
- Coveralls.wear! unless ENV["SIMPLE_COVERAGE"]
5
+ Coveralls.wear! unless ENV['SIMPLE_COVERAGE']
6
6
 
7
7
  begin
8
- if ENV["SIMPLE_COVERAGE"]
8
+ if ENV['SIMPLE_COVERAGE']
9
9
  require 'simplecov'
10
10
  SimpleCov.start do
11
- add_group "Lib", "lib"
11
+ add_group 'Lib', 'lib'
12
12
 
13
- add_filter "/spec/"
13
+ add_filter '/spec/'
14
14
  end
15
15
  end
16
16
  rescue LoadError
17
- warn "=" * 80
17
+ warn '=' * 80
18
18
  warn 'simplecov not installed. No coverage report'
19
- warn "=" * 80
19
+ warn '=' * 80
20
20
  end
21
21
 
22
22
  require 'yaoc'
23
23
 
24
- Dir[File.join(File.expand_path(__dir__ ), "support/**/*.rb")].each { |f| require f }
24
+ Dir[File.join(File.expand_path(__dir__), 'support/**/*.rb')].each { |f| require f }
25
25
 
26
26
  # This file was generated by the `rspec --init` command. Conventionally, all
27
27
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
@@ -16,7 +16,6 @@ module Capybara
16
16
  end
17
17
  end
18
18
 
19
-
20
19
  def self.feature(*args, &block)
21
20
  options = if args.last.is_a?(Hash) then args.pop else {} end
22
21
  options[:capybara_feature] = true
@@ -27,4 +26,4 @@ def self.feature(*args, &block)
27
26
  describe(*args, &block)
28
27
  end
29
28
 
30
- RSpec.configuration.include Capybara::Features, :capybara_feature => true
29
+ RSpec.configuration.include Capybara::Features, capybara_feature: true