praxis-mapper 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +26 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +4 -0
  5. data/CHANGELOG.md +83 -0
  6. data/Gemfile +3 -0
  7. data/Gemfile.lock +102 -0
  8. data/Guardfile +11 -0
  9. data/LICENSE +22 -0
  10. data/README.md +19 -0
  11. data/Rakefile +14 -0
  12. data/lib/praxis-mapper/config_hash.rb +40 -0
  13. data/lib/praxis-mapper/connection_manager.rb +102 -0
  14. data/lib/praxis-mapper/finalizable.rb +38 -0
  15. data/lib/praxis-mapper/identity_map.rb +532 -0
  16. data/lib/praxis-mapper/logging.rb +22 -0
  17. data/lib/praxis-mapper/model.rb +430 -0
  18. data/lib/praxis-mapper/query/base.rb +213 -0
  19. data/lib/praxis-mapper/query/sql.rb +183 -0
  20. data/lib/praxis-mapper/query_statistics.rb +46 -0
  21. data/lib/praxis-mapper/resource.rb +226 -0
  22. data/lib/praxis-mapper/support/factory_girl.rb +104 -0
  23. data/lib/praxis-mapper/support/memory_query.rb +34 -0
  24. data/lib/praxis-mapper/support/memory_repository.rb +44 -0
  25. data/lib/praxis-mapper/support/schema_dumper.rb +66 -0
  26. data/lib/praxis-mapper/support/schema_loader.rb +56 -0
  27. data/lib/praxis-mapper/support.rb +2 -0
  28. data/lib/praxis-mapper/version.rb +5 -0
  29. data/lib/praxis-mapper.rb +60 -0
  30. data/praxis-mapper.gemspec +38 -0
  31. data/spec/praxis-mapper/connection_manager_spec.rb +117 -0
  32. data/spec/praxis-mapper/identity_map_spec.rb +905 -0
  33. data/spec/praxis-mapper/logging_spec.rb +9 -0
  34. data/spec/praxis-mapper/memory_repository_spec.rb +56 -0
  35. data/spec/praxis-mapper/model_spec.rb +389 -0
  36. data/spec/praxis-mapper/query/base_spec.rb +317 -0
  37. data/spec/praxis-mapper/query/sql_spec.rb +184 -0
  38. data/spec/praxis-mapper/resource_spec.rb +154 -0
  39. data/spec/praxis_mapper_spec.rb +21 -0
  40. data/spec/spec_fixtures.rb +12 -0
  41. data/spec/spec_helper.rb +63 -0
  42. data/spec/support/spec_models.rb +215 -0
  43. data/spec/support/spec_resources.rb +39 -0
  44. metadata +298 -0
@@ -0,0 +1,63 @@
1
+ Encoding.default_external = Encoding::UTF_8
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+
6
+ # Configure simplecov gem (must be here at top of file)
7
+ #require 'simplecov'
8
+ #SimpleCov.start do
9
+ # add_filter 'spec' # Don't include RSpec stuff
10
+ #end
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+
15
+
16
+
17
+ Bundler.setup
18
+
19
+ #Bundler.require(:default, :development, :test)
20
+
21
+
22
+ require 'praxis-mapper'
23
+ require 'active_support/core_ext/kernel'
24
+
25
+ require_relative 'support/spec_models'
26
+ require_relative 'support/spec_resources'
27
+ require_relative 'spec_fixtures'
28
+
29
+ require 'praxis-mapper/support'
30
+
31
+ require 'randexp'
32
+
33
+ require 'pry'
34
+
35
+ RSpec.configure do |config|
36
+ config.backtrace_exclusion_patterns = [
37
+ /\/lib\d*\/ruby\//,
38
+ /bin\//,
39
+ /gems/,
40
+ /spec\/spec_helper\.rb/,
41
+ /lib\/rspec\/(core|expectations|matchers|mocks)/,
42
+ /org\/jruby\/.*.java/
43
+ ]
44
+
45
+ config.before(:suite) do
46
+ Praxis::Mapper.finalize!
47
+
48
+ Praxis::Mapper::ConnectionManager.repository(:default, query: Praxis::Mapper::Support::MemoryQuery) do
49
+ Praxis::Mapper::Support::MemoryRepository.new
50
+ end
51
+
52
+ Praxis::Mapper::ConnectionManager.repository(:sql) do
53
+ Sequel.mock
54
+ end
55
+
56
+ Praxis::Mapper::IdentityMap.setup!
57
+ end
58
+
59
+ config.after(:each) do
60
+ Praxis::Mapper::IdentityMap.current.clear!
61
+ end
62
+
63
+ end
@@ -0,0 +1,215 @@
1
+ # A set of model classes for use in specs
2
+ class ParentModel < Praxis::Mapper::Model
3
+ table_name 'parent_model'
4
+ identity :id
5
+ end
6
+
7
+
8
+ class YamlArrayModel < Praxis::Mapper::Model
9
+ table_name 'yaml_array_model'
10
+ identity :id
11
+
12
+ silence_warnings do
13
+ belongs_to :parents, :model => ParentModel,
14
+ :source_key => :parent_ids,
15
+ :fk => :id,
16
+ :type => :array
17
+
18
+ belongs_to :grandparents, :model => ParentModel,
19
+ :source_key => :grandparent_ids,
20
+ :fk => :id,
21
+ :type => :array
22
+ end
23
+
24
+ yaml :parent_ids, :default => []
25
+ yaml :grandparent_ids
26
+ yaml :names
27
+
28
+ end
29
+
30
+
31
+ class JsonArrayModel < Praxis::Mapper::Model
32
+ table_name 'json_array_model'
33
+ identity :id
34
+
35
+ silence_warnings do
36
+ belongs_to :parents, :model => ParentModel,
37
+ :source_key => :parent_ids,
38
+ :fk => :id,
39
+ :type => :array
40
+ end
41
+
42
+ json :parent_ids, :default => []
43
+ json :names
44
+
45
+ end
46
+
47
+
48
+ class CompositeIdModel < Praxis::Mapper::Model
49
+ table_name 'composite_id_model'
50
+ identity [:id,:type]
51
+
52
+ one_to_many :other_models do
53
+ model OtherModel
54
+ primary_key [:id, :type]
55
+ key [:composite_id, :composite_type]
56
+ end
57
+
58
+ many_to_array :composite_array_models do
59
+ model CompositeArrayModel
60
+ primary_key [:id, :type]
61
+ key :composite_array_keys
62
+ end
63
+
64
+ end
65
+
66
+
67
+ class CompositeArrayModel < Praxis::Mapper::Model
68
+ table_name 'composite_array_model'
69
+ identity [:id,:type]
70
+
71
+
72
+ array_to_many :composite_id_models do
73
+ model CompositeIdModel
74
+ primary_key [:id, :type]
75
+ key :composite_array_keys
76
+ end
77
+
78
+ json :composite_array_keys
79
+
80
+ end
81
+
82
+
83
+ class OtherModel < Praxis::Mapper::Model
84
+ table_name 'other_model'
85
+ identity :name
86
+
87
+ silence_warnings do
88
+ belongs_to :composite_model, :model => CompositeIdModel,
89
+ :source_key => [:composite_id, :composite_type],
90
+ :fk => [:id, :type]
91
+ end
92
+
93
+ end
94
+
95
+
96
+ class SimpleModel < Praxis::Mapper::Model
97
+ table_name 'simple_model'
98
+ identity :id
99
+ identity :name
100
+
101
+ excluded_scopes :account
102
+
103
+ silence_warnings do
104
+ belongs_to :parent, :model => ParentModel,
105
+ :source_key => :parent_id,
106
+ :fk => :id
107
+ belongs_to :other_model, :model => OtherModel,
108
+ :source_key => :other_name,
109
+ :fk => :name
110
+ end
111
+
112
+ end
113
+
114
+
115
+ class SimplerModel < Praxis::Mapper::Model
116
+ table_name 'simpler_model'
117
+ identity :id
118
+ identity :name
119
+ end
120
+
121
+
122
+ class PersonModel < Praxis::Mapper::Model
123
+ table_name 'people'
124
+
125
+ identity :id
126
+ identity :email
127
+
128
+ many_to_one :address do
129
+ model AddressModel
130
+ key :address_id # people.address_id
131
+ end
132
+
133
+ one_to_many :properties do
134
+ model AddressModel
135
+ primary_key :id #people.id
136
+ key :owner_id # address.owner_id
137
+ end
138
+
139
+ array_to_many :prior_addresses do
140
+ model AddressModel
141
+ key :prior_address_ids # people.prior_address_ids
142
+ end
143
+
144
+ json :prior_address_ids, default: []
145
+
146
+
147
+ context :default do
148
+ track :address
149
+ end
150
+
151
+
152
+ context :addresses do
153
+ select :id, :name
154
+
155
+ track :address do
156
+ context :default
157
+ end
158
+
159
+ track :prior_addresses
160
+ end
161
+
162
+
163
+ context :tiny do
164
+ select :id, :email
165
+ end
166
+
167
+ context :current do
168
+ select :id
169
+ end
170
+
171
+ end
172
+
173
+
174
+ class AddressModel < Praxis::Mapper::Model
175
+ table_name 'addresses'
176
+ identity :id
177
+
178
+ one_to_many :residents do
179
+ model PersonModel
180
+ key :address_id # person.address_id
181
+ end
182
+
183
+ many_to_one :owner do
184
+ model PersonModel
185
+ primary_key :id
186
+ key :owner_id # address.owner_id
187
+ end
188
+
189
+ many_to_array :prior_residents do
190
+ model PersonModel
191
+ key :prior_address_ids # people.prior_address_ids
192
+ end
193
+
194
+ context :default do
195
+ track :owner
196
+ end
197
+
198
+ context :current do
199
+ track :owner do
200
+ context :default
201
+ end
202
+ track :residents do
203
+ context :tiny
204
+ end
205
+ end
206
+
207
+ end
208
+
209
+ class ItemModel < Praxis::Mapper::Model
210
+ table_name 'items'
211
+ repository_name :sql
212
+
213
+ identity :id
214
+
215
+ end
@@ -0,0 +1,39 @@
1
+ # A set of resource classes for use in specs
2
+ class BaseResource < Praxis::Mapper::Resource
3
+ def href
4
+ base_href = '' # "/api"
5
+ base_href + "/#{self.class.collection_name}/#{self.id}"
6
+ end
7
+
8
+ end
9
+
10
+ class CompositeIdResource < BaseResource
11
+ model CompositeIdModel
12
+ end
13
+
14
+ class OtherResource < BaseResource
15
+ model OtherModel
16
+ end
17
+
18
+ class ParentResource < BaseResource
19
+ model ParentModel
20
+ end
21
+
22
+ class SimpleResource < BaseResource
23
+ model SimpleModel
24
+
25
+ resource_delegate :other_model => [:other_attribute]
26
+
27
+ def other_resource
28
+ self.other_model
29
+ end
30
+
31
+ end
32
+
33
+ class SimplerResource < BaseResource
34
+ model SimplerModel
35
+ end
36
+
37
+ class YamlArrayResource < BaseResource
38
+ model YamlArrayModel
39
+ end
metadata ADDED
@@ -0,0 +1,298 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: praxis-mapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Josep M. Blanquer
8
+ - Dane Jensen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-08-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: randexp
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: sequel
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '4'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '4'
42
+ - !ruby/object:Gem::Dependency
43
+ name: activesupport
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '4'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '4'
56
+ - !ruby/object:Gem::Dependency
57
+ name: bundler
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.6'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.6'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: redcarpet
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "<"
89
+ - !ruby/object:Gem::Version
90
+ version: '3.0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "<"
96
+ - !ruby/object:Gem::Version
97
+ version: '3.0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: yard
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: 0.8.7
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: 0.8.7
112
+ - !ruby/object:Gem::Dependency
113
+ name: guard
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '2'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '2'
126
+ - !ruby/object:Gem::Dependency
127
+ name: guard-rspec
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: rspec
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - "<"
145
+ - !ruby/object:Gem::Version
146
+ version: '2.99'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "<"
152
+ - !ruby/object:Gem::Version
153
+ version: '2.99'
154
+ - !ruby/object:Gem::Dependency
155
+ name: pry
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - "~>"
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - "~>"
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ - !ruby/object:Gem::Dependency
169
+ name: pry-byebug
170
+ requirement: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - "~>"
173
+ - !ruby/object:Gem::Version
174
+ version: '1'
175
+ type: :development
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - "~>"
180
+ - !ruby/object:Gem::Version
181
+ version: '1'
182
+ - !ruby/object:Gem::Dependency
183
+ name: pry-stack_explorer
184
+ requirement: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - "~>"
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ type: :development
190
+ prerelease: false
191
+ version_requirements: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - "~>"
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ - !ruby/object:Gem::Dependency
197
+ name: fuubar
198
+ requirement: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - "~>"
201
+ - !ruby/object:Gem::Version
202
+ version: '1'
203
+ type: :development
204
+ prerelease: false
205
+ version_requirements: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - "~>"
208
+ - !ruby/object:Gem::Version
209
+ version: '1'
210
+ description:
211
+ email:
212
+ - blanquer@gmail.com
213
+ - dane.jensen@gmail.com
214
+ executables: []
215
+ extensions: []
216
+ extra_rdoc_files: []
217
+ files:
218
+ - ".gitignore"
219
+ - ".rspec"
220
+ - ".travis.yml"
221
+ - CHANGELOG.md
222
+ - Gemfile
223
+ - Gemfile.lock
224
+ - Guardfile
225
+ - LICENSE
226
+ - README.md
227
+ - Rakefile
228
+ - lib/praxis-mapper.rb
229
+ - lib/praxis-mapper/config_hash.rb
230
+ - lib/praxis-mapper/connection_manager.rb
231
+ - lib/praxis-mapper/finalizable.rb
232
+ - lib/praxis-mapper/identity_map.rb
233
+ - lib/praxis-mapper/logging.rb
234
+ - lib/praxis-mapper/model.rb
235
+ - lib/praxis-mapper/query/base.rb
236
+ - lib/praxis-mapper/query/sql.rb
237
+ - lib/praxis-mapper/query_statistics.rb
238
+ - lib/praxis-mapper/resource.rb
239
+ - lib/praxis-mapper/support.rb
240
+ - lib/praxis-mapper/support/factory_girl.rb
241
+ - lib/praxis-mapper/support/memory_query.rb
242
+ - lib/praxis-mapper/support/memory_repository.rb
243
+ - lib/praxis-mapper/support/schema_dumper.rb
244
+ - lib/praxis-mapper/support/schema_loader.rb
245
+ - lib/praxis-mapper/version.rb
246
+ - praxis-mapper.gemspec
247
+ - spec/praxis-mapper/connection_manager_spec.rb
248
+ - spec/praxis-mapper/identity_map_spec.rb
249
+ - spec/praxis-mapper/logging_spec.rb
250
+ - spec/praxis-mapper/memory_repository_spec.rb
251
+ - spec/praxis-mapper/model_spec.rb
252
+ - spec/praxis-mapper/query/base_spec.rb
253
+ - spec/praxis-mapper/query/sql_spec.rb
254
+ - spec/praxis-mapper/resource_spec.rb
255
+ - spec/praxis_mapper_spec.rb
256
+ - spec/spec_fixtures.rb
257
+ - spec/spec_helper.rb
258
+ - spec/support/spec_models.rb
259
+ - spec/support/spec_resources.rb
260
+ homepage: https://github.com/rightscale/praxis-mapper
261
+ licenses:
262
+ - MIT
263
+ metadata: {}
264
+ post_install_message:
265
+ rdoc_options: []
266
+ require_paths:
267
+ - lib
268
+ required_ruby_version: !ruby/object:Gem::Requirement
269
+ requirements:
270
+ - - ">="
271
+ - !ruby/object:Gem::Version
272
+ version: '2.1'
273
+ required_rubygems_version: !ruby/object:Gem::Requirement
274
+ requirements:
275
+ - - ">="
276
+ - !ruby/object:Gem::Version
277
+ version: '0'
278
+ requirements: []
279
+ rubyforge_project:
280
+ rubygems_version: 2.2.1
281
+ signing_key:
282
+ specification_version: 4
283
+ summary: A multi-datastore library designed for efficiency in loading large datasets.
284
+ test_files:
285
+ - spec/praxis-mapper/connection_manager_spec.rb
286
+ - spec/praxis-mapper/identity_map_spec.rb
287
+ - spec/praxis-mapper/logging_spec.rb
288
+ - spec/praxis-mapper/memory_repository_spec.rb
289
+ - spec/praxis-mapper/model_spec.rb
290
+ - spec/praxis-mapper/query/base_spec.rb
291
+ - spec/praxis-mapper/query/sql_spec.rb
292
+ - spec/praxis-mapper/resource_spec.rb
293
+ - spec/praxis_mapper_spec.rb
294
+ - spec/spec_fixtures.rb
295
+ - spec/spec_helper.rb
296
+ - spec/support/spec_models.rb
297
+ - spec/support/spec_resources.rb
298
+ has_rdoc: