vorpal 0.1.0.rc3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  require 'vorpal/engine'
2
2
  require 'vorpal/dsl/config_builder'
3
+ require 'vorpal/driver/postgresql'
3
4
 
4
5
  module Vorpal
5
6
  module Dsl
@@ -9,12 +10,12 @@ module Vorpal
9
10
  #
10
11
  # @param options [Hash] Global configuration options for the engine instance.
11
12
  # @option options [Object] :db_driver (Object that will be used to interact with the DB.)
12
- # Must be duck-type compatible with {DbDriver}.
13
+ # Must be duck-type compatible with {Postgresql}.
13
14
  #
14
15
  # @return [Engine] Instance of the mapping engine.
15
16
  def define(options={}, &block)
16
17
  master_config = build_config(&block)
17
- db_driver = options.fetch(:db_driver, DbDriver.new)
18
+ db_driver = options.fetch(:db_driver, Driver::Postgresql.new)
18
19
  Engine.new(db_driver, master_config)
19
20
  end
20
21
 
@@ -40,7 +41,7 @@ module Vorpal
40
41
 
41
42
  # @private
42
43
  def build_class_config(domain_class, options={}, &block)
43
- builder = ConfigBuilder.new(domain_class, options, DbDriver.new)
44
+ builder = ConfigBuilder.new(domain_class, options, Driver::Postgresql.new)
44
45
  builder.instance_exec(&block) if block_given?
45
46
  builder.build
46
47
  end
@@ -53,4 +54,4 @@ module Vorpal
53
54
  end
54
55
  end
55
56
  end
56
- end
57
+ end
@@ -1,6 +1,6 @@
1
1
  require 'simple_serializer/serializer'
2
2
  require 'simple_serializer/deserializer'
3
- require 'active_support/inflector/methods'
3
+ require 'active_support'
4
4
  require 'active_support/core_ext/module/introspection'
5
5
 
6
6
  module Vorpal
@@ -36,9 +36,19 @@ module Vorpal
36
36
  end
37
37
 
38
38
  def child_class(association_name)
39
- # Module#parent comes from 'active_support/core_ext/module/introspection'
40
- parent_module = @domain_class.parent
41
- parent_module.const_get(ActiveSupport::Inflector.classify(association_name.to_s))
39
+ module_parent.const_get(ActiveSupport::Inflector.classify(association_name.to_s))
40
+ end
41
+
42
+ private
43
+
44
+ def module_parent
45
+ if (ActiveSupport::VERSION::MAJOR == 5)
46
+ # Module#parent comes from 'active_support/core_ext/module/introspection'
47
+ @domain_class.parent
48
+ else
49
+ # Module#module_parent comes from 'active_support/core_ext/module/introspection'
50
+ @domain_class.module_parent
51
+ end
42
52
  end
43
53
  end
44
54
  end
@@ -1,7 +1,6 @@
1
1
  require 'vorpal/identity_map'
2
2
  require 'vorpal/aggregate_utils'
3
3
  require 'vorpal/db_loader'
4
- require 'vorpal/db_driver'
5
4
  require 'vorpal/aggregate_mapper'
6
5
  require 'vorpal/exceptions'
7
6
 
@@ -80,7 +79,7 @@ module Vorpal
80
79
 
81
80
  loaded_db_objects = load_owned_from_db(ids, domain_class)
82
81
  loaded_db_objects.each do |config, db_objects|
83
- @db_driver.destroy(config, db_objects.map(&:id))
82
+ @db_driver.destroy(config.db_class, db_objects.map(&:id))
84
83
  end
85
84
  ids
86
85
  end
@@ -91,7 +90,7 @@ module Vorpal
91
90
  end
92
91
 
93
92
  def query(domain_class)
94
- @db_driver.query(@configs.config_for(domain_class), mapper_for(domain_class))
93
+ @db_driver.query(@configs.config_for(domain_class).db_class, mapper_for(domain_class))
95
94
  end
96
95
 
97
96
  private
@@ -166,7 +165,7 @@ module Vorpal
166
165
  def set_primary_keys(owned_objects, mapping)
167
166
  owned_objects.each do |config, objects|
168
167
  in_need_of_primary_keys = objects.find_all { |obj| obj.id.nil? }
169
- primary_keys = @db_driver.get_primary_keys(config, in_need_of_primary_keys.length)
168
+ primary_keys = @db_driver.get_primary_keys(config.db_class, in_need_of_primary_keys.length)
170
169
  in_need_of_primary_keys.zip(primary_keys).each do |object, primary_key|
171
170
  mapping[object].id = primary_key
172
171
  object.id = primary_key
@@ -207,11 +206,11 @@ module Vorpal
207
206
  owned_objects.each do |config, objects|
208
207
  objects_to_insert = grouped_new_objects[config] || []
209
208
  db_objects_to_insert = objects_to_insert.map { |obj| mapping[obj] }
210
- @db_driver.insert(config, db_objects_to_insert)
209
+ @db_driver.insert(config.db_class, db_objects_to_insert)
211
210
 
212
211
  objects_to_update = objects - objects_to_insert
213
212
  db_objects_to_update = objects_to_update.map { |obj| mapping[obj] }
214
- @db_driver.update(config, db_objects_to_update)
213
+ @db_driver.update(config.db_class, db_objects_to_update)
215
214
  end
216
215
  end
217
216
 
@@ -221,7 +220,7 @@ module Vorpal
221
220
  all_orphans = db_objects_in_db - db_objects_in_aggregate
222
221
  grouped_orphans = all_orphans.group_by { |o| @configs.config_for_db_object(o) }
223
222
  grouped_orphans.each do |config, orphans|
224
- @db_driver.destroy(config, orphans)
223
+ @db_driver.destroy(config.db_class, orphans)
225
224
  end
226
225
  end
227
226
 
@@ -234,4 +233,4 @@ module Vorpal
234
233
  objects.each { |object| object.id = nil }
235
234
  end
236
235
  end
237
- end
236
+ end
@@ -1,22 +1,23 @@
1
1
  module Vorpal
2
+ # Maps DB rows to Entities
2
3
  class IdentityMap
3
4
  def initialize
4
5
  @entities = {}
5
6
  end
6
7
 
7
- def get(key_object)
8
- @entities[key(key_object)]
8
+ def get(db_row)
9
+ @entities[key(db_row)]
9
10
  end
10
11
 
11
- def set(key_object, object)
12
- @entities[key(key_object)] = object
12
+ def set(db_row, entity)
13
+ @entities[key(db_row)] = entity
13
14
  end
14
15
 
15
- def get_and_set(key_object)
16
- object = get(key_object)
17
- object = yield if object.nil?
18
- set(key_object, object)
19
- object
16
+ def get_and_set(db_row)
17
+ entity = get(db_row)
18
+ entity = yield if entity.nil?
19
+ set(db_row, entity)
20
+ entity
20
21
  end
21
22
 
22
23
  def map(key_objects)
@@ -25,11 +26,11 @@ module Vorpal
25
26
 
26
27
  private
27
28
 
28
- def key(key_object)
29
- return nil unless key_object
30
- raise "Cannot put entity '#{key_object.inspect}' into IdentityMap without an id." if key_object.id.nil?
31
- raise "Cannot put entity '#{key_object.inspect}' into IdentityMap without a Class with a name." if key_object.class.name.nil?
32
- [key_object.id, key_object.class.name]
29
+ def key(db_row)
30
+ return nil unless db_row
31
+ raise "Cannot map a DB row without an id '#{db_row.inspect}' to an entity." if db_row.id.nil?
32
+ raise "Cannot map a DB row without a Class with a name '#{db_row.inspect}' to an entity." if db_row.class.name.nil?
33
+ [db_row.id, db_row.class.name]
33
34
  end
34
35
  end
35
36
  end
@@ -1,3 +1,3 @@
1
1
  module Vorpal
2
- VERSION = "0.1.0.rc3"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -13,19 +13,23 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://github.com/nulogy/vorpal"
14
14
  spec.license = "MIT"
15
15
 
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.files = Dir["CHANGELOG.md", "LICENSE.txt", "README.md", "vorpal.gemspec", "lib/**/*"]
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_runtime_dependency "simple_serializer", "~> 1.0"
22
22
  spec.add_runtime_dependency "equalizer"
23
23
  spec.add_runtime_dependency "activesupport"
24
24
 
25
- spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rake", "~> 13"
26
26
  spec.add_development_dependency "rspec", "~> 3.0"
27
- spec.add_development_dependency "activerecord", "~> 4.0"
28
- spec.add_development_dependency "pg", "~> 0.17.0"
29
27
  spec.add_development_dependency "virtus", "~> 1.0"
30
- spec.add_development_dependency "activerecord-import", "~> 0.10.0"
28
+ spec.add_development_dependency "appraisal", "~> 2.2"
29
+
30
+ spec.required_ruby_version = ">= 2.5.7"
31
+ spec.add_development_dependency "activerecord"
32
+ spec.add_development_dependency "pg"
33
+ spec.add_development_dependency "activerecord-import"
34
+ spec.add_development_dependency "codecov"
31
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vorpal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.rc3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Kirby
8
- autorequire:
9
- bindir: bin
8
+ autorequire:
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-11 00:00:00.000000000 Z
11
+ date: 2020-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simple_serializer
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '13'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: '13'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -81,61 +81,89 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: activerecord
84
+ name: virtus
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '4.0'
89
+ version: '1.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '4.0'
96
+ version: '1.0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: pg
98
+ name: appraisal
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.17.0
103
+ version: '2.2'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 0.17.0
110
+ version: '2.2'
111
111
  - !ruby/object:Gem::Dependency
112
- name: virtus
112
+ name: activerecord
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: '1.0'
117
+ version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: '1.0'
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pg
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: activerecord-import
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
- - - "~>"
143
+ - - ">="
130
144
  - !ruby/object:Gem::Version
131
- version: 0.10.0
145
+ version: '0'
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
- - - "~>"
150
+ - - ">="
137
151
  - !ruby/object:Gem::Version
138
- version: 0.10.0
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: codecov
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
139
167
  description: An ORM framelet that fits on top of ActiveRecord to give you 'Data Mapper'
140
168
  semantics.
141
169
  email:
@@ -144,23 +172,16 @@ executables: []
144
172
  extensions: []
145
173
  extra_rdoc_files: []
146
174
  files:
147
- - ".editorconfig"
148
- - ".gitignore"
149
- - ".rspec"
150
- - ".ruby-version"
151
- - ".yardopts"
152
175
  - CHANGELOG.md
153
- - Gemfile
154
176
  - LICENSE.txt
155
177
  - README.md
156
- - Rakefile
157
178
  - lib/vorpal.rb
158
179
  - lib/vorpal/aggregate_mapper.rb
159
180
  - lib/vorpal/aggregate_traversal.rb
160
181
  - lib/vorpal/aggregate_utils.rb
161
182
  - lib/vorpal/configs.rb
162
- - lib/vorpal/db_driver.rb
163
183
  - lib/vorpal/db_loader.rb
184
+ - lib/vorpal/driver/postgresql.rb
164
185
  - lib/vorpal/dsl/config_builder.rb
165
186
  - lib/vorpal/dsl/configuration.rb
166
187
  - lib/vorpal/dsl/defaults_generator.rb
@@ -172,26 +193,12 @@ files:
172
193
  - lib/vorpal/util/hash_initialization.rb
173
194
  - lib/vorpal/util/string_utils.rb
174
195
  - lib/vorpal/version.rb
175
- - spec/helpers/db_helpers.rb
176
- - spec/helpers/profile_helpers.rb
177
- - spec/integration_spec_helper.rb
178
- - spec/unit_spec_helper.rb
179
- - spec/vorpal/acceptance/aggregate_mapper_spec.rb
180
- - spec/vorpal/integration/db_driver_spec.rb
181
- - spec/vorpal/performance/performance_spec.rb
182
- - spec/vorpal/unit/configs_spec.rb
183
- - spec/vorpal/unit/db_loader_spec.rb
184
- - spec/vorpal/unit/dsl/config_builder_spec.rb
185
- - spec/vorpal/unit/dsl/defaults_generator_spec.rb
186
- - spec/vorpal/unit/identity_map_spec.rb
187
- - spec/vorpal/unit/loaded_objects_spec.rb
188
- - spec/vorpal/unit/util/string_utils_spec.rb
189
196
  - vorpal.gemspec
190
197
  homepage: https://github.com/nulogy/vorpal
191
198
  licenses:
192
199
  - MIT
193
200
  metadata: {}
194
- post_install_message:
201
+ post_install_message:
195
202
  rdoc_options: []
196
203
  require_paths:
197
204
  - lib
@@ -199,30 +206,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
199
206
  requirements:
200
207
  - - ">="
201
208
  - !ruby/object:Gem::Version
202
- version: '0'
209
+ version: 2.5.7
203
210
  required_rubygems_version: !ruby/object:Gem::Requirement
204
211
  requirements:
205
- - - ">"
212
+ - - ">="
206
213
  - !ruby/object:Gem::Version
207
- version: 1.3.1
214
+ version: '0'
208
215
  requirements: []
209
- rubyforge_project:
210
- rubygems_version: 2.4.8
211
- signing_key:
216
+ rubygems_version: 3.1.2
217
+ signing_key:
212
218
  specification_version: 4
213
219
  summary: Separate your domain model from your persistence mechanism.
214
- test_files:
215
- - spec/helpers/db_helpers.rb
216
- - spec/helpers/profile_helpers.rb
217
- - spec/integration_spec_helper.rb
218
- - spec/unit_spec_helper.rb
219
- - spec/vorpal/acceptance/aggregate_mapper_spec.rb
220
- - spec/vorpal/integration/db_driver_spec.rb
221
- - spec/vorpal/performance/performance_spec.rb
222
- - spec/vorpal/unit/configs_spec.rb
223
- - spec/vorpal/unit/db_loader_spec.rb
224
- - spec/vorpal/unit/dsl/config_builder_spec.rb
225
- - spec/vorpal/unit/dsl/defaults_generator_spec.rb
226
- - spec/vorpal/unit/identity_map_spec.rb
227
- - spec/vorpal/unit/loaded_objects_spec.rb
228
- - spec/vorpal/unit/util/string_utils_spec.rb
220
+ test_files: []
@@ -1,13 +0,0 @@
1
- root = true
2
-
3
- [*]
4
-
5
- indent_style = space
6
- indent_size = 2
7
- end_of_line = lf
8
- charset = utf-8
9
- trim_trailing_whitespace = true
10
- insert_final_newline = true
11
-
12
- [*.md]
13
- trim_trailing_whitespace = false