vorpal 1.0.3 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +73 -26
  3. data/lib/vorpal/aggregate_mapper.rb +13 -2
  4. data/lib/vorpal/aggregate_traversal.rb +9 -8
  5. data/lib/vorpal/config/association_config.rb +84 -0
  6. data/lib/vorpal/config/belongs_to_config.rb +35 -0
  7. data/lib/vorpal/config/class_config.rb +71 -0
  8. data/lib/vorpal/config/configs.rb +54 -0
  9. data/lib/vorpal/config/foreign_key_info.rb +23 -0
  10. data/lib/vorpal/config/has_many_config.rb +38 -0
  11. data/lib/vorpal/config/has_one_config.rb +35 -0
  12. data/lib/vorpal/config/main_config.rb +68 -0
  13. data/lib/vorpal/db_loader.rb +25 -22
  14. data/lib/vorpal/driver/postgresql.rb +42 -6
  15. data/lib/vorpal/dsl/config_builder.rb +26 -73
  16. data/lib/vorpal/dsl/configuration.rb +139 -42
  17. data/lib/vorpal/dsl/defaults_generator.rb +1 -1
  18. data/lib/vorpal/engine.rb +27 -13
  19. data/lib/vorpal/exceptions.rb +4 -0
  20. data/lib/vorpal/loaded_objects.rb +57 -14
  21. data/lib/vorpal/util/array_hash.rb +22 -8
  22. data/lib/vorpal/util/hash_initialization.rb +1 -1
  23. data/lib/vorpal/version.rb +1 -1
  24. data/vorpal.gemspec +4 -4
  25. metadata +17 -74
  26. data/.editorconfig +0 -13
  27. data/.envrc +0 -4
  28. data/.gitignore +0 -16
  29. data/.rspec +0 -1
  30. data/.ruby-version +0 -1
  31. data/.travis.yml +0 -18
  32. data/.yardopts +0 -1
  33. data/Appraisals +0 -18
  34. data/Gemfile +0 -4
  35. data/Rakefile +0 -39
  36. data/bin/appraisal +0 -29
  37. data/bin/rake +0 -29
  38. data/bin/rspec +0 -29
  39. data/docker-compose.yml +0 -19
  40. data/gemfiles/rails_5_1.gemfile +0 -11
  41. data/gemfiles/rails_5_1.gemfile.lock +0 -101
  42. data/gemfiles/rails_5_2.gemfile +0 -11
  43. data/gemfiles/rails_5_2.gemfile.lock +0 -101
  44. data/gemfiles/rails_6_0.gemfile +0 -9
  45. data/gemfiles/rails_6_0.gemfile.lock +0 -101
  46. data/lib/vorpal/configs.rb +0 -296
  47. data/spec/acceptance/vorpal/aggregate_mapper_spec.rb +0 -910
  48. data/spec/helpers/codecov_helper.rb +0 -7
  49. data/spec/helpers/db_helpers.rb +0 -69
  50. data/spec/helpers/profile_helpers.rb +0 -26
  51. data/spec/integration/vorpal/driver/postgresql_spec.rb +0 -42
  52. data/spec/integration_spec_helper.rb +0 -29
  53. data/spec/performance/vorpal/performance_spec.rb +0 -305
  54. data/spec/unit/vorpal/configs_spec.rb +0 -117
  55. data/spec/unit/vorpal/db_loader_spec.rb +0 -103
  56. data/spec/unit/vorpal/dsl/config_builder_spec.rb +0 -18
  57. data/spec/unit/vorpal/dsl/defaults_generator_spec.rb +0 -75
  58. data/spec/unit/vorpal/identity_map_spec.rb +0 -62
  59. data/spec/unit/vorpal/loaded_objects_spec.rb +0 -22
  60. data/spec/unit/vorpal/util/string_utils_spec.rb +0 -25
  61. data/spec/unit_spec_helper.rb +0 -1
@@ -1,101 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- vorpal (1.0.3)
5
- activesupport
6
- equalizer
7
- simple_serializer (~> 1.0)
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- activemodel (5.1.7)
13
- activesupport (= 5.1.7)
14
- activerecord (5.1.7)
15
- activemodel (= 5.1.7)
16
- activesupport (= 5.1.7)
17
- arel (~> 8.0)
18
- activerecord-import (0.13.0)
19
- activerecord (>= 3.0)
20
- activesupport (5.1.7)
21
- concurrent-ruby (~> 1.0, >= 1.0.2)
22
- i18n (>= 0.7, < 2)
23
- minitest (~> 5.1)
24
- tzinfo (~> 1.1)
25
- appraisal (2.2.0)
26
- bundler
27
- rake
28
- thor (>= 0.14.0)
29
- arel (8.0.0)
30
- axiom-types (0.1.1)
31
- descendants_tracker (~> 0.0.4)
32
- ice_nine (~> 0.11.0)
33
- thread_safe (~> 0.3, >= 0.3.1)
34
- codecov (0.1.16)
35
- json
36
- simplecov
37
- url
38
- coercible (1.0.0)
39
- descendants_tracker (~> 0.0.1)
40
- concurrent-ruby (1.1.5)
41
- descendants_tracker (0.0.4)
42
- thread_safe (~> 0.3, >= 0.3.1)
43
- diff-lcs (1.3)
44
- docile (1.3.2)
45
- equalizer (0.0.11)
46
- i18n (1.8.2)
47
- concurrent-ruby (~> 1.0)
48
- ice_nine (0.11.2)
49
- json (2.3.0)
50
- minitest (5.14.0)
51
- pg (0.18.4)
52
- rake (10.5.0)
53
- rspec (3.8.0)
54
- rspec-core (~> 3.8.0)
55
- rspec-expectations (~> 3.8.0)
56
- rspec-mocks (~> 3.8.0)
57
- rspec-core (3.8.0)
58
- rspec-support (~> 3.8.0)
59
- rspec-expectations (3.8.1)
60
- diff-lcs (>= 1.2.0, < 2.0)
61
- rspec-support (~> 3.8.0)
62
- rspec-mocks (3.8.0)
63
- diff-lcs (>= 1.2.0, < 2.0)
64
- rspec-support (~> 3.8.0)
65
- rspec-support (3.8.0)
66
- simple_serializer (1.0.2)
67
- simplecov (0.17.1)
68
- docile (~> 1.1)
69
- json (>= 1.8, < 3)
70
- simplecov-html (~> 0.10.0)
71
- simplecov-html (0.10.2)
72
- thor (0.20.0)
73
- thread_safe (0.3.6)
74
- tzinfo (1.2.6)
75
- thread_safe (~> 0.1)
76
- url (0.3.2)
77
- virtus (1.0.5)
78
- axiom-types (~> 0.1)
79
- coercible (~> 1.0)
80
- descendants_tracker (~> 0.0, >= 0.0.3)
81
- equalizer (~> 0.0, >= 0.0.9)
82
-
83
- PLATFORMS
84
- ruby
85
-
86
- DEPENDENCIES
87
- activerecord (~> 5.1.0)
88
- activerecord-import (= 0.13.0)
89
- appraisal (~> 2.2)
90
- codecov
91
- pg (~> 0.18.0)
92
- rake (~> 10)
93
- rspec (~> 3.0)
94
- virtus (~> 1.0)
95
- vorpal!
96
-
97
- RUBY VERSION
98
- ruby 2.6.3p62
99
-
100
- BUNDLED WITH
101
- 1.17.2
@@ -1,11 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- ruby ">= 2.5.7"
6
-
7
- gem "activerecord", "~> 5.2.0"
8
- gem "pg", "~> 0.18.0"
9
- gem "activerecord-import", "= 0.13.0"
10
-
11
- gemspec path: "../"
@@ -1,101 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- vorpal (1.0.3)
5
- activesupport
6
- equalizer
7
- simple_serializer (~> 1.0)
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- activemodel (5.2.4.1)
13
- activesupport (= 5.2.4.1)
14
- activerecord (5.2.4.1)
15
- activemodel (= 5.2.4.1)
16
- activesupport (= 5.2.4.1)
17
- arel (>= 9.0)
18
- activerecord-import (0.13.0)
19
- activerecord (>= 3.0)
20
- activesupport (5.2.4.1)
21
- concurrent-ruby (~> 1.0, >= 1.0.2)
22
- i18n (>= 0.7, < 2)
23
- minitest (~> 5.1)
24
- tzinfo (~> 1.1)
25
- appraisal (2.2.0)
26
- bundler
27
- rake
28
- thor (>= 0.14.0)
29
- arel (9.0.0)
30
- axiom-types (0.1.1)
31
- descendants_tracker (~> 0.0.4)
32
- ice_nine (~> 0.11.0)
33
- thread_safe (~> 0.3, >= 0.3.1)
34
- codecov (0.1.16)
35
- json
36
- simplecov
37
- url
38
- coercible (1.0.0)
39
- descendants_tracker (~> 0.0.1)
40
- concurrent-ruby (1.1.5)
41
- descendants_tracker (0.0.4)
42
- thread_safe (~> 0.3, >= 0.3.1)
43
- diff-lcs (1.3)
44
- docile (1.3.2)
45
- equalizer (0.0.11)
46
- i18n (1.8.2)
47
- concurrent-ruby (~> 1.0)
48
- ice_nine (0.11.2)
49
- json (2.3.0)
50
- minitest (5.14.0)
51
- pg (0.18.4)
52
- rake (10.5.0)
53
- rspec (3.8.0)
54
- rspec-core (~> 3.8.0)
55
- rspec-expectations (~> 3.8.0)
56
- rspec-mocks (~> 3.8.0)
57
- rspec-core (3.8.0)
58
- rspec-support (~> 3.8.0)
59
- rspec-expectations (3.8.1)
60
- diff-lcs (>= 1.2.0, < 2.0)
61
- rspec-support (~> 3.8.0)
62
- rspec-mocks (3.8.0)
63
- diff-lcs (>= 1.2.0, < 2.0)
64
- rspec-support (~> 3.8.0)
65
- rspec-support (3.8.0)
66
- simple_serializer (1.0.2)
67
- simplecov (0.17.1)
68
- docile (~> 1.1)
69
- json (>= 1.8, < 3)
70
- simplecov-html (~> 0.10.0)
71
- simplecov-html (0.10.2)
72
- thor (0.20.0)
73
- thread_safe (0.3.6)
74
- tzinfo (1.2.6)
75
- thread_safe (~> 0.1)
76
- url (0.3.2)
77
- virtus (1.0.5)
78
- axiom-types (~> 0.1)
79
- coercible (~> 1.0)
80
- descendants_tracker (~> 0.0, >= 0.0.3)
81
- equalizer (~> 0.0, >= 0.0.9)
82
-
83
- PLATFORMS
84
- ruby
85
-
86
- DEPENDENCIES
87
- activerecord (~> 5.2.0)
88
- activerecord-import (= 0.13.0)
89
- appraisal (~> 2.2)
90
- codecov
91
- pg (~> 0.18.0)
92
- rake (~> 10)
93
- rspec (~> 3.0)
94
- virtus (~> 1.0)
95
- vorpal!
96
-
97
- RUBY VERSION
98
- ruby 2.6.3p62
99
-
100
- BUNDLED WITH
101
- 1.17.2
@@ -1,9 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- ruby ">= 2.7.0"
6
-
7
- gem "activerecord", "~> 6.0.0"
8
-
9
- gemspec path: "../"
@@ -1,101 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- vorpal (1.0.3)
5
- activesupport
6
- equalizer
7
- simple_serializer (~> 1.0)
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- activemodel (6.0.2.1)
13
- activesupport (= 6.0.2.1)
14
- activerecord (6.0.2.1)
15
- activemodel (= 6.0.2.1)
16
- activesupport (= 6.0.2.1)
17
- activerecord-import (1.0.4)
18
- activerecord (>= 3.2)
19
- activesupport (6.0.2.1)
20
- concurrent-ruby (~> 1.0, >= 1.0.2)
21
- i18n (>= 0.7, < 2)
22
- minitest (~> 5.1)
23
- tzinfo (~> 1.1)
24
- zeitwerk (~> 2.2)
25
- appraisal (2.2.0)
26
- bundler
27
- rake
28
- thor (>= 0.14.0)
29
- axiom-types (0.1.1)
30
- descendants_tracker (~> 0.0.4)
31
- ice_nine (~> 0.11.0)
32
- thread_safe (~> 0.3, >= 0.3.1)
33
- codecov (0.1.16)
34
- json
35
- simplecov
36
- url
37
- coercible (1.0.0)
38
- descendants_tracker (~> 0.0.1)
39
- concurrent-ruby (1.1.5)
40
- descendants_tracker (0.0.4)
41
- thread_safe (~> 0.3, >= 0.3.1)
42
- diff-lcs (1.3)
43
- docile (1.3.2)
44
- equalizer (0.0.11)
45
- i18n (1.8.2)
46
- concurrent-ruby (~> 1.0)
47
- ice_nine (0.11.2)
48
- json (2.3.0)
49
- minitest (5.14.0)
50
- pg (1.2.2)
51
- rake (10.5.0)
52
- rspec (3.9.0)
53
- rspec-core (~> 3.9.0)
54
- rspec-expectations (~> 3.9.0)
55
- rspec-mocks (~> 3.9.0)
56
- rspec-core (3.9.1)
57
- rspec-support (~> 3.9.1)
58
- rspec-expectations (3.9.0)
59
- diff-lcs (>= 1.2.0, < 2.0)
60
- rspec-support (~> 3.9.0)
61
- rspec-mocks (3.9.1)
62
- diff-lcs (>= 1.2.0, < 2.0)
63
- rspec-support (~> 3.9.0)
64
- rspec-support (3.9.2)
65
- simple_serializer (1.0.2)
66
- simplecov (0.17.1)
67
- docile (~> 1.1)
68
- json (>= 1.8, < 3)
69
- simplecov-html (~> 0.10.0)
70
- simplecov-html (0.10.2)
71
- thor (1.0.1)
72
- thread_safe (0.3.6)
73
- tzinfo (1.2.6)
74
- thread_safe (~> 0.1)
75
- url (0.3.2)
76
- virtus (1.0.5)
77
- axiom-types (~> 0.1)
78
- coercible (~> 1.0)
79
- descendants_tracker (~> 0.0, >= 0.0.3)
80
- equalizer (~> 0.0, >= 0.0.9)
81
- zeitwerk (2.2.2)
82
-
83
- PLATFORMS
84
- ruby
85
-
86
- DEPENDENCIES
87
- activerecord (~> 6.0.0)
88
- activerecord-import
89
- appraisal (~> 2.2)
90
- codecov
91
- pg
92
- rake (~> 10)
93
- rspec (~> 3.0)
94
- virtus (~> 1.0)
95
- vorpal!
96
-
97
- RUBY VERSION
98
- ruby 2.7.0p0
99
-
100
- BUNDLED WITH
101
- 2.1.4
@@ -1,296 +0,0 @@
1
- require 'vorpal/util/hash_initialization'
2
- require 'vorpal/exceptions'
3
- require 'equalizer'
4
-
5
- module Vorpal
6
- # @private
7
- class MasterConfig
8
- def initialize(class_configs)
9
- @class_configs = class_configs
10
- initialize_association_configs
11
- end
12
-
13
- def config_for(clazz)
14
- config = @class_configs.detect { |conf| conf.domain_class == clazz }
15
- raise Vorpal::ConfigurationNotFound.new("No configuration found for #{clazz}") unless config
16
- config
17
- end
18
-
19
- def config_for_db_object(db_object)
20
- @class_configs.detect { |conf| conf.db_class == db_object.class }
21
- end
22
-
23
- private
24
-
25
- def initialize_association_configs
26
- association_configs = {}
27
- @class_configs.each do |config|
28
- (config.has_ones + config.has_manys).each do |association_end_config|
29
- child_config = config_for(association_end_config.child_class)
30
- association_end_config.set_parent_class_config(config)
31
-
32
- association_config = build_association_config(association_configs, child_config, association_end_config.fk, association_end_config.fk_type)
33
- association_config.remote_end_config = association_end_config
34
- association_config.add_remote_class_config(config)
35
- association_end_config.association_config = association_config
36
- end
37
-
38
- config.belongs_tos.each do |association_end_config|
39
- child_configs = association_end_config.child_classes.map(&method(:config_for))
40
-
41
- association_config = build_association_config(association_configs, config, association_end_config.fk, association_end_config.fk_type)
42
- association_config.local_end_config = association_end_config
43
- association_config.add_remote_class_config(child_configs)
44
- association_end_config.association_config = association_config
45
- end
46
- end
47
-
48
- association_configs.values.each do |association_config|
49
- association_config.local_class_config.local_association_configs << association_config
50
- end
51
- end
52
-
53
- def build_association_config(association_configs, local_config, fk, fk_type)
54
- association_config = AssociationConfig.new(local_config, fk, fk_type)
55
- if association_configs[association_config]
56
- association_config = association_configs[association_config]
57
- else
58
- association_configs[association_config] = association_config
59
- end
60
- association_config
61
- end
62
- end
63
-
64
- # @private
65
- # Object associations:
66
- # - All object associations are uni-directional
67
- # - The end that holds the association is the 'Parent' and the end that
68
- # is referred to is the 'Child' or 'Children'
69
- #
70
- # Relational associations:
71
- # - Local end: has FK
72
- # - Remote end: has no FK
73
- #
74
- class AssociationConfig
75
- include Equalizer.new(:local_class_config, :fk)
76
-
77
- attr_reader :local_class_config, :remote_class_configs, :fk
78
-
79
- # Only one of these two attributes needs to be specified
80
- # If one is specified, then the association is uni-directional.
81
- # If both are specified, then the association is bi-directional.
82
- attr_accessor :local_end_config, :remote_end_config
83
-
84
- def initialize(local_class_config, fk, fk_type)
85
- @local_class_config = local_class_config
86
- @remote_class_configs = {}
87
- @fk = fk
88
- @fk_type = fk_type
89
- end
90
-
91
- def fk_value(local_db_object)
92
- local_db_object.send(fk)
93
- end
94
-
95
- def associate(local_object, remote_object)
96
- local_end_config.associate(local_object, remote_object) if local_end_config && local_object
97
- remote_end_config.associate(remote_object, local_object) if remote_end_config && remote_object
98
- end
99
-
100
- def add_remote_class_config(remote_class_configs)
101
- Array(remote_class_configs).each do |remote_class_config|
102
- @remote_class_configs[remote_class_config.domain_class.name] = remote_class_config
103
- end
104
- end
105
-
106
- def remote_class_config(local_db_object)
107
- if polymorphic?
108
- fk_type_value = local_db_object.send(@fk_type)
109
- @remote_class_configs[fk_type_value]
110
- else
111
- @remote_class_configs.values.first
112
- end
113
- end
114
-
115
- def polymorphic?
116
- !@fk_type.nil?
117
- end
118
-
119
- def set_foreign_key(local_db_object, remote_object)
120
- local_class_config.set_attribute(local_db_object, @fk, remote_object.try(:id))
121
- local_class_config.set_attribute(local_db_object, @fk_type, remote_object.class.name) if polymorphic?
122
- end
123
-
124
- def foreign_key_info(remote_class_config)
125
- ForeignKeyInfo.new(@fk, @fk_type, remote_class_config.domain_class.name, polymorphic?)
126
- end
127
- end
128
-
129
- # @private
130
- class ClassConfig
131
- include Equalizer.new(:domain_class, :db_class)
132
- attr_reader :serializer, :deserializer, :domain_class, :db_class, :local_association_configs
133
- attr_accessor :has_manys, :belongs_tos, :has_ones
134
-
135
- def initialize(attrs)
136
- @has_manys = []
137
- @belongs_tos = []
138
- @has_ones = []
139
- @local_association_configs = []
140
-
141
- attrs.each do |k,v|
142
- instance_variable_set("@#{k}", v)
143
- end
144
- end
145
-
146
- def build_db_object(attributes)
147
- db_class.new(attributes)
148
- end
149
-
150
- def set_db_object_attributes(db_object, attributes)
151
- db_object.attributes = attributes
152
- end
153
-
154
- def get_db_object_attributes(db_object)
155
- symbolize_keys(db_object.attributes)
156
- end
157
-
158
- def serialization_required?
159
- domain_class.superclass.name != 'ActiveRecord::Base'
160
- end
161
-
162
- def serialize(object)
163
- serializer.serialize(object)
164
- end
165
-
166
- def deserialize(db_object)
167
- attributes = get_db_object_attributes(db_object)
168
- serialization_required? ? deserializer.deserialize(domain_class.new, attributes) : db_object
169
- end
170
-
171
- def set_attribute(db_object, attribute, value)
172
- db_object.send("#{attribute}=", value)
173
- end
174
-
175
- def get_attribute(db_object, attribute)
176
- db_object.send(attribute)
177
- end
178
-
179
- private
180
-
181
- def symbolize_keys(hash)
182
- result = {}
183
- hash.each_key do |key|
184
- result[key.to_sym] = hash[key]
185
- end
186
- result
187
- end
188
- end
189
-
190
- # @private
191
- class ForeignKeyInfo
192
- include Equalizer.new(:fk_column, :fk_type_column, :fk_type)
193
-
194
- attr_reader :fk_column, :fk_type_column, :fk_type, :polymorphic
195
-
196
- def initialize(fk_column, fk_type_column, fk_type, polymorphic)
197
- @fk_column = fk_column
198
- @fk_type_column = fk_type_column
199
- @fk_type = fk_type
200
- @polymorphic = polymorphic
201
- end
202
-
203
- def polymorphic?
204
- @polymorphic
205
- end
206
- end
207
-
208
- # @private
209
- module RemoteEndConfig
210
- def child_config
211
- association_config.local_class_config
212
- end
213
-
214
- def set_foreign_key(db_child, parent)
215
- association_config.set_foreign_key(db_child, parent)
216
- end
217
-
218
- def set_parent_class_config(parent_config)
219
- @parent_config = parent_config
220
- end
221
-
222
- def foreign_key_info
223
- association_config.foreign_key_info(@parent_config)
224
- end
225
- end
226
-
227
- # @private
228
- module LocalEndConfig
229
- def child_config(db_parent)
230
- association_config.remote_class_config(db_parent)
231
- end
232
-
233
- def set_foreign_key(db_parent, child)
234
- association_config.set_foreign_key(db_parent, child)
235
- end
236
-
237
- def fk_value(db_parent)
238
- db_parent.send(fk)
239
- end
240
- end
241
-
242
- # @private
243
- module ToOneConfig
244
- def get_child(parent)
245
- parent.send(name)
246
- end
247
-
248
- def associate(parent, child)
249
- parent.send("#{name}=", child)
250
- end
251
- end
252
-
253
- # @private
254
- module ToManyConfig
255
- def get_children(parent)
256
- parent.send(name)
257
- end
258
-
259
- def associate(parent, child)
260
- if get_children(parent).nil?
261
- parent.send("#{name}=", [])
262
- end
263
- get_children(parent) << child
264
- end
265
- end
266
-
267
- # @private
268
- class HasManyConfig
269
- include Util::HashInitialization
270
- include RemoteEndConfig
271
- include ToManyConfig
272
-
273
- attr_reader :name, :owned, :fk, :fk_type, :child_class
274
- attr_accessor :association_config
275
- end
276
-
277
- # @private
278
- class HasOneConfig
279
- include Util::HashInitialization
280
- include RemoteEndConfig
281
- include ToOneConfig
282
-
283
- attr_reader :name, :owned, :fk, :fk_type, :child_class
284
- attr_accessor :association_config
285
- end
286
-
287
- # @private
288
- class BelongsToConfig
289
- include Util::HashInitialization
290
- include LocalEndConfig
291
- include ToOneConfig
292
-
293
- attr_reader :name, :owned, :fk, :fk_type, :child_classes
294
- attr_accessor :association_config
295
- end
296
- end