rom 2.0.2 → 3.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -4
- data/CHANGELOG.md +34 -1
- data/Gemfile +16 -2
- data/Rakefile +7 -2
- data/lib/rom/array_dataset.rb +44 -0
- data/lib/rom/association_set.rb +11 -5
- data/lib/rom/auto_curry.rb +55 -0
- data/lib/rom/command.rb +70 -41
- data/lib/rom/command_registry.rb +7 -18
- data/lib/rom/commands/class_interface.rb +7 -6
- data/lib/rom/commands/composite.rb +0 -1
- data/lib/rom/commands/graph.rb +7 -15
- data/lib/rom/commands/lazy/update.rb +1 -1
- data/lib/rom/configuration_dsl/command.rb +6 -8
- data/lib/rom/configuration_dsl/mapper.rb +2 -3
- data/lib/rom/configuration_dsl/mapper_dsl.rb +0 -1
- data/lib/rom/configuration_dsl/relation.rb +4 -4
- data/lib/rom/configuration_dsl.rb +0 -4
- data/lib/rom/constants.rb +1 -1
- data/lib/rom/container.rb +0 -2
- data/lib/rom/create_container.rb +0 -2
- data/lib/rom/data_proxy.rb +94 -0
- data/lib/rom/enumerable_dataset.rb +68 -0
- data/lib/rom/gateway.rb +23 -6
- data/lib/rom/global/plugin_dsl.rb +0 -2
- data/lib/rom/global.rb +0 -2
- data/lib/rom/initializer.rb +26 -0
- data/lib/rom/lint/gateway.rb +17 -0
- data/lib/rom/mapper_registry.rb +1 -1
- data/lib/rom/memory/commands.rb +0 -2
- data/lib/rom/memory/dataset.rb +1 -2
- data/lib/rom/memory/relation.rb +14 -1
- data/lib/rom/memory/schema.rb +13 -0
- data/lib/rom/plugin_registry.rb +1 -1
- data/lib/rom/plugins/configuration/configuration_dsl.rb +6 -2
- data/lib/rom/plugins/relation/key_inference.rb +4 -2
- data/lib/rom/plugins/relation/registry_reader.rb +5 -1
- data/lib/rom/registry.rb +50 -0
- data/lib/rom/relation/class_interface.rb +94 -26
- data/lib/rom/relation/curried.rb +15 -15
- data/lib/rom/relation/view_dsl.rb +31 -0
- data/lib/rom/relation.rb +49 -34
- data/lib/rom/schema/dsl.rb +7 -9
- data/lib/rom/schema/type.rb +115 -0
- data/lib/rom/schema.rb +218 -18
- data/lib/rom/setup/auto_registration.rb +20 -17
- data/lib/rom/setup/auto_registration_strategies/base.rb +8 -3
- data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +4 -3
- data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +5 -4
- data/lib/rom/setup/auto_registration_strategies/with_namespace.rb +3 -3
- data/lib/rom/setup/finalize/finalize_commands.rb +1 -1
- data/lib/rom/setup/finalize/finalize_mappers.rb +1 -1
- data/lib/rom/setup/finalize/finalize_relations.rb +3 -1
- data/lib/rom/setup/finalize.rb +1 -1
- data/lib/rom/transaction.rb +24 -0
- data/lib/rom/types.rb +9 -1
- data/lib/rom/version.rb +1 -1
- data/lib/rom.rb +4 -8
- data/rom.gemspec +4 -3
- data/spec/integration/command_registry_spec.rb +1 -14
- data/spec/integration/commands/create_spec.rb +5 -25
- data/spec/integration/commands/delete_spec.rb +1 -1
- data/spec/integration/commands/error_handling_spec.rb +1 -1
- data/spec/integration/commands/graph_spec.rb +20 -14
- data/spec/integration/commands/update_spec.rb +4 -27
- data/spec/integration/commands_spec.rb +1 -1
- data/spec/integration/{repositories → gateways}/extending_relations_spec.rb +1 -1
- data/spec/integration/{repositories → gateways}/setting_logger_spec.rb +2 -2
- data/spec/integration/mappers/combine_spec.rb +1 -1
- data/spec/integration/mappers/deep_embedded_spec.rb +1 -1
- data/spec/integration/mappers/definition_dsl_spec.rb +1 -1
- data/spec/integration/mappers/embedded_spec.rb +1 -1
- data/spec/integration/mappers/exclude_spec.rb +1 -1
- data/spec/integration/mappers/fold_spec.rb +1 -1
- data/spec/integration/mappers/group_spec.rb +1 -1
- data/spec/integration/mappers/overwrite_attributes_value_spec.rb +1 -1
- data/spec/integration/mappers/prefix_separator_spec.rb +1 -1
- data/spec/integration/mappers/prefix_spec.rb +1 -1
- data/spec/integration/mappers/prefixing_attributes_spec.rb +1 -1
- data/spec/integration/mappers/registering_custom_mappers_spec.rb +1 -1
- data/spec/integration/mappers/renaming_attributes_spec.rb +1 -1
- data/spec/integration/mappers/reusing_mappers_spec.rb +1 -1
- data/spec/integration/mappers/step_spec.rb +1 -1
- data/spec/integration/mappers/symbolizing_attributes_spec.rb +1 -1
- data/spec/integration/mappers/unfold_spec.rb +1 -1
- data/spec/integration/mappers/ungroup_spec.rb +1 -1
- data/spec/integration/mappers/unwrap_spec.rb +2 -2
- data/spec/integration/mappers/wrap_spec.rb +1 -1
- data/spec/integration/memory/commands/create_spec.rb +1 -1
- data/spec/integration/memory/commands/delete_spec.rb +1 -1
- data/spec/integration/memory/commands/update_spec.rb +1 -1
- data/spec/integration/multi_env_spec.rb +1 -1
- data/spec/integration/multi_repo_spec.rb +1 -1
- data/spec/integration/relations/default_dataset_spec.rb +1 -1
- data/spec/integration/relations/reading_spec.rb +1 -1
- data/spec/integration/relations/registry_dsl_spec.rb +1 -1
- data/spec/integration/setup_spec.rb +10 -4
- data/spec/shared/command_graph.rb +8 -4
- data/spec/shared/enumerable_dataset.rb +1 -1
- data/spec/spec_helper.rb +7 -9
- data/spec/support/schema.rb +14 -0
- data/spec/unit/rom/array_dataset_spec.rb +59 -0
- data/spec/unit/rom/association_set_spec.rb +4 -0
- data/spec/unit/rom/auto_curry_spec.rb +63 -0
- data/spec/unit/rom/commands/graph_spec.rb +12 -11
- data/spec/unit/rom/commands/lazy_spec.rb +8 -5
- data/spec/unit/rom/commands/pre_and_post_processors_spec.rb +269 -0
- data/spec/unit/rom/commands/result_spec.rb +1 -1
- data/spec/unit/rom/commands_spec.rb +9 -3
- data/spec/unit/rom/configuration_spec.rb +1 -1
- data/spec/unit/rom/container_spec.rb +11 -5
- data/spec/unit/rom/create_container_spec.rb +1 -1
- data/spec/unit/rom/enumerable_dataset_spec.rb +15 -0
- data/spec/unit/rom/gateway_spec.rb +1 -1
- data/spec/unit/rom/mapper_registry_spec.rb +1 -1
- data/spec/unit/rom/memory/commands_spec.rb +1 -1
- data/spec/unit/rom/memory/dataset_spec.rb +1 -1
- data/spec/unit/rom/memory/{repository_spec.rb → gateway_spec.rb} +1 -1
- data/spec/unit/rom/memory/inheritance_spec.rb +32 -0
- data/spec/unit/rom/memory/relation_spec.rb +15 -3
- data/spec/unit/rom/memory/storage_spec.rb +1 -1
- data/spec/unit/rom/plugin_spec.rb +1 -1
- data/spec/unit/rom/plugins/relation/key_inference_spec.rb +1 -1
- data/spec/unit/rom/registry_spec.rb +86 -0
- data/spec/unit/rom/relation/attribute_reader_spec.rb +17 -0
- data/spec/unit/rom/relation/composite_spec.rb +1 -1
- data/spec/unit/rom/relation/graph_spec.rb +1 -1
- data/spec/unit/rom/relation/lazy/combine_spec.rb +1 -1
- data/spec/unit/rom/relation/lazy_spec.rb +1 -1
- data/spec/unit/rom/relation/loaded_spec.rb +1 -1
- data/spec/unit/rom/relation/schema_spec.rb +10 -6
- data/spec/unit/rom/relation/view_spec.rb +112 -0
- data/spec/unit/rom/relation_spec.rb +16 -2
- data/spec/unit/rom/schema/accessing_attributes_spec.rb +52 -0
- data/spec/unit/rom/schema/exclude_spec.rb +15 -0
- data/spec/unit/rom/schema/finalize_spec.rb +59 -0
- data/spec/unit/rom/schema/key_predicate_spec.rb +15 -0
- data/spec/unit/rom/schema/merge_spec.rb +17 -0
- data/spec/unit/rom/schema/prefix_spec.rb +16 -0
- data/spec/unit/rom/schema/project_spec.rb +15 -0
- data/spec/unit/rom/schema/rename_spec.rb +22 -0
- data/spec/unit/rom/schema/type_spec.rb +49 -0
- data/spec/unit/rom/schema/wrap_spec.rb +17 -0
- data/spec/unit/rom/schema_spec.rb +2 -2
- metadata +69 -17
- data/lib/rom/plugins/relation/view/dsl.rb +0 -32
- data/lib/rom/plugins/relation/view.rb +0 -95
- data/spec/unit/rom/plugins/relation/view_spec.rb +0 -51
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -53,33 +53,59 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.8'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: dry-core
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '2
|
61
|
+
version: '0.2'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 0.2.3
|
62
65
|
type: :runtime
|
63
66
|
prerelease: false
|
64
67
|
version_requirements: !ruby/object:Gem::Requirement
|
65
68
|
requirements:
|
66
69
|
- - "~>"
|
67
70
|
- !ruby/object:Gem::Version
|
68
|
-
version: '2
|
71
|
+
version: '0.2'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 0.2.3
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: dry-initializer
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0.10'
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 0.10.2
|
85
|
+
type: :runtime
|
86
|
+
prerelease: false
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - "~>"
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0.10'
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 0.10.2
|
69
95
|
- !ruby/object:Gem::Dependency
|
70
96
|
name: rom-mapper
|
71
97
|
requirement: !ruby/object:Gem::Requirement
|
72
98
|
requirements:
|
73
99
|
- - "~>"
|
74
100
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
101
|
+
version: 0.5.0.beta
|
76
102
|
type: :runtime
|
77
103
|
prerelease: false
|
78
104
|
version_requirements: !ruby/object:Gem::Requirement
|
79
105
|
requirements:
|
80
106
|
- - "~>"
|
81
107
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
108
|
+
version: 0.5.0.beta
|
83
109
|
- !ruby/object:Gem::Dependency
|
84
110
|
name: rake
|
85
111
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,14 +126,14 @@ dependencies:
|
|
100
126
|
requirements:
|
101
127
|
- - "~>"
|
102
128
|
- !ruby/object:Gem::Version
|
103
|
-
version: '3.
|
129
|
+
version: '3.5'
|
104
130
|
type: :development
|
105
131
|
prerelease: false
|
106
132
|
version_requirements: !ruby/object:Gem::Requirement
|
107
133
|
requirements:
|
108
134
|
- - "~>"
|
109
135
|
- !ruby/object:Gem::Version
|
110
|
-
version: '3.
|
136
|
+
version: '3.5'
|
111
137
|
description: Persistence and mapping toolkit for Ruby
|
112
138
|
email: piotr.solnica@gmail.com
|
113
139
|
executables: []
|
@@ -128,7 +154,9 @@ files:
|
|
128
154
|
- README.md
|
129
155
|
- Rakefile
|
130
156
|
- lib/rom.rb
|
157
|
+
- lib/rom/array_dataset.rb
|
131
158
|
- lib/rom/association_set.rb
|
159
|
+
- lib/rom/auto_curry.rb
|
132
160
|
- lib/rom/command.rb
|
133
161
|
- lib/rom/command_registry.rb
|
134
162
|
- lib/rom/commands.rb
|
@@ -157,10 +185,13 @@ files:
|
|
157
185
|
- lib/rom/constants.rb
|
158
186
|
- lib/rom/container.rb
|
159
187
|
- lib/rom/create_container.rb
|
188
|
+
- lib/rom/data_proxy.rb
|
189
|
+
- lib/rom/enumerable_dataset.rb
|
160
190
|
- lib/rom/environment.rb
|
161
191
|
- lib/rom/gateway.rb
|
162
192
|
- lib/rom/global.rb
|
163
193
|
- lib/rom/global/plugin_dsl.rb
|
194
|
+
- lib/rom/initializer.rb
|
164
195
|
- lib/rom/lint/enumerable_dataset.rb
|
165
196
|
- lib/rom/lint/gateway.rb
|
166
197
|
- lib/rom/lint/linter.rb
|
@@ -172,6 +203,7 @@ files:
|
|
172
203
|
- lib/rom/memory/dataset.rb
|
173
204
|
- lib/rom/memory/gateway.rb
|
174
205
|
- lib/rom/memory/relation.rb
|
206
|
+
- lib/rom/memory/schema.rb
|
175
207
|
- lib/rom/memory/storage.rb
|
176
208
|
- lib/rom/memory/types.rb
|
177
209
|
- lib/rom/pipeline.rb
|
@@ -182,8 +214,7 @@ files:
|
|
182
214
|
- lib/rom/plugins/configuration/configuration_dsl.rb
|
183
215
|
- lib/rom/plugins/relation/key_inference.rb
|
184
216
|
- lib/rom/plugins/relation/registry_reader.rb
|
185
|
-
- lib/rom/
|
186
|
-
- lib/rom/plugins/relation/view/dsl.rb
|
217
|
+
- lib/rom/registry.rb
|
187
218
|
- lib/rom/relation.rb
|
188
219
|
- lib/rom/relation/class_interface.rb
|
189
220
|
- lib/rom/relation/composite.rb
|
@@ -192,9 +223,11 @@ files:
|
|
192
223
|
- lib/rom/relation/loaded.rb
|
193
224
|
- lib/rom/relation/materializable.rb
|
194
225
|
- lib/rom/relation/name.rb
|
226
|
+
- lib/rom/relation/view_dsl.rb
|
195
227
|
- lib/rom/relation_registry.rb
|
196
228
|
- lib/rom/schema.rb
|
197
229
|
- lib/rom/schema/dsl.rb
|
230
|
+
- lib/rom/schema/type.rb
|
198
231
|
- lib/rom/setup.rb
|
199
232
|
- lib/rom/setup/auto_registration.rb
|
200
233
|
- lib/rom/setup/auto_registration_strategies/base.rb
|
@@ -206,6 +239,7 @@ files:
|
|
206
239
|
- lib/rom/setup/finalize/finalize_mappers.rb
|
207
240
|
- lib/rom/setup/finalize/finalize_relations.rb
|
208
241
|
- lib/rom/support/configurable.rb
|
242
|
+
- lib/rom/transaction.rb
|
209
243
|
- lib/rom/types.rb
|
210
244
|
- lib/rom/version.rb
|
211
245
|
- log/.gitkeep
|
@@ -236,6 +270,8 @@ files:
|
|
236
270
|
- spec/integration/commands/graph_spec.rb
|
237
271
|
- spec/integration/commands/update_spec.rb
|
238
272
|
- spec/integration/commands_spec.rb
|
273
|
+
- spec/integration/gateways/extending_relations_spec.rb
|
274
|
+
- spec/integration/gateways/setting_logger_spec.rb
|
239
275
|
- spec/integration/mappers/combine_spec.rb
|
240
276
|
- spec/integration/mappers/deep_embedded_spec.rb
|
241
277
|
- spec/integration/mappers/definition_dsl_spec.rb
|
@@ -265,8 +301,6 @@ files:
|
|
265
301
|
- spec/integration/relations/inheritance_spec.rb
|
266
302
|
- spec/integration/relations/reading_spec.rb
|
267
303
|
- spec/integration/relations/registry_dsl_spec.rb
|
268
|
-
- spec/integration/repositories/extending_relations_spec.rb
|
269
|
-
- spec/integration/repositories/setting_logger_spec.rb
|
270
304
|
- spec/integration/setup_spec.rb
|
271
305
|
- spec/shared/command_behavior.rb
|
272
306
|
- spec/shared/command_graph.rb
|
@@ -281,29 +315,36 @@ files:
|
|
281
315
|
- spec/spec_helper.rb
|
282
316
|
- spec/support/constant_leak_finder.rb
|
283
317
|
- spec/support/mutant.rb
|
318
|
+
- spec/support/schema.rb
|
284
319
|
- spec/support/types.rb
|
285
320
|
- spec/test/memory_repository_lint_test.rb
|
321
|
+
- spec/unit/rom/array_dataset_spec.rb
|
286
322
|
- spec/unit/rom/association_set_spec.rb
|
323
|
+
- spec/unit/rom/auto_curry_spec.rb
|
287
324
|
- spec/unit/rom/commands/graph_spec.rb
|
288
325
|
- spec/unit/rom/commands/lazy_spec.rb
|
326
|
+
- spec/unit/rom/commands/pre_and_post_processors_spec.rb
|
289
327
|
- spec/unit/rom/commands/result_spec.rb
|
290
328
|
- spec/unit/rom/commands_spec.rb
|
291
329
|
- spec/unit/rom/configurable_spec.rb
|
292
330
|
- spec/unit/rom/configuration_spec.rb
|
293
331
|
- spec/unit/rom/container_spec.rb
|
294
332
|
- spec/unit/rom/create_container_spec.rb
|
333
|
+
- spec/unit/rom/enumerable_dataset_spec.rb
|
295
334
|
- spec/unit/rom/environment_spec.rb
|
296
335
|
- spec/unit/rom/gateway_spec.rb
|
297
336
|
- spec/unit/rom/mapper_registry_spec.rb
|
298
337
|
- spec/unit/rom/memory/commands_spec.rb
|
299
338
|
- spec/unit/rom/memory/dataset_spec.rb
|
339
|
+
- spec/unit/rom/memory/gateway_spec.rb
|
340
|
+
- spec/unit/rom/memory/inheritance_spec.rb
|
300
341
|
- spec/unit/rom/memory/relation_spec.rb
|
301
|
-
- spec/unit/rom/memory/repository_spec.rb
|
302
342
|
- spec/unit/rom/memory/storage_spec.rb
|
303
343
|
- spec/unit/rom/plugin_spec.rb
|
304
344
|
- spec/unit/rom/plugins/command/schema_spec.rb
|
305
345
|
- spec/unit/rom/plugins/relation/key_inference_spec.rb
|
306
|
-
- spec/unit/rom/
|
346
|
+
- spec/unit/rom/registry_spec.rb
|
347
|
+
- spec/unit/rom/relation/attribute_reader_spec.rb
|
307
348
|
- spec/unit/rom/relation/composite_spec.rb
|
308
349
|
- spec/unit/rom/relation/curried_spec.rb
|
309
350
|
- spec/unit/rom/relation/graph_spec.rb
|
@@ -312,7 +353,18 @@ files:
|
|
312
353
|
- spec/unit/rom/relation/loaded_spec.rb
|
313
354
|
- spec/unit/rom/relation/name_spec.rb
|
314
355
|
- spec/unit/rom/relation/schema_spec.rb
|
356
|
+
- spec/unit/rom/relation/view_spec.rb
|
315
357
|
- spec/unit/rom/relation_spec.rb
|
358
|
+
- spec/unit/rom/schema/accessing_attributes_spec.rb
|
359
|
+
- spec/unit/rom/schema/exclude_spec.rb
|
360
|
+
- spec/unit/rom/schema/finalize_spec.rb
|
361
|
+
- spec/unit/rom/schema/key_predicate_spec.rb
|
362
|
+
- spec/unit/rom/schema/merge_spec.rb
|
363
|
+
- spec/unit/rom/schema/prefix_spec.rb
|
364
|
+
- spec/unit/rom/schema/project_spec.rb
|
365
|
+
- spec/unit/rom/schema/rename_spec.rb
|
366
|
+
- spec/unit/rom/schema/type_spec.rb
|
367
|
+
- spec/unit/rom/schema/wrap_spec.rb
|
316
368
|
- spec/unit/rom/schema_spec.rb
|
317
369
|
- spec/unit/rom/setup/auto_registration_spec.rb
|
318
370
|
homepage: http://rom-rb.org
|
@@ -330,9 +382,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
330
382
|
version: '0'
|
331
383
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
332
384
|
requirements:
|
333
|
-
- - "
|
385
|
+
- - ">"
|
334
386
|
- !ruby/object:Gem::Version
|
335
|
-
version:
|
387
|
+
version: 1.3.1
|
336
388
|
requirements: []
|
337
389
|
rubyforge_project:
|
338
390
|
rubygems_version: 2.5.1
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module ROM
|
2
|
-
module Plugins
|
3
|
-
module Relation
|
4
|
-
module View
|
5
|
-
class DSL
|
6
|
-
attr_reader :name
|
7
|
-
|
8
|
-
attr_reader :attributes
|
9
|
-
|
10
|
-
attr_reader :relation_block
|
11
|
-
|
12
|
-
def initialize(name, &block)
|
13
|
-
@name = name
|
14
|
-
instance_eval(&block)
|
15
|
-
end
|
16
|
-
|
17
|
-
def header(*args, &block)
|
18
|
-
@attributes = args.size > 0 ? args.first : block
|
19
|
-
end
|
20
|
-
|
21
|
-
def relation(&block)
|
22
|
-
@relation_block = lambda(&block)
|
23
|
-
end
|
24
|
-
|
25
|
-
def call
|
26
|
-
[name, attributes, relation_block]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,95 +0,0 @@
|
|
1
|
-
require 'rom/plugins/relation/view/dsl'
|
2
|
-
|
3
|
-
module ROM
|
4
|
-
module Plugins
|
5
|
-
module Relation
|
6
|
-
module View
|
7
|
-
def self.included(klass)
|
8
|
-
super
|
9
|
-
|
10
|
-
klass.class_eval do
|
11
|
-
extend ClassInterface
|
12
|
-
|
13
|
-
option :view, reader: true
|
14
|
-
option :attributes
|
15
|
-
|
16
|
-
def self.attributes
|
17
|
-
@__attributes__ ||= {}
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
# Return column names that will be selected for this relation
|
23
|
-
#
|
24
|
-
# By default we use dataset columns but first we look at configured
|
25
|
-
# attributes by `view` DSL
|
26
|
-
#
|
27
|
-
# @return [Array<Symbol>]
|
28
|
-
#
|
29
|
-
# @api private
|
30
|
-
def attributes(view_name = view)
|
31
|
-
if options.key?(:attributes)
|
32
|
-
options[:attributes]
|
33
|
-
else
|
34
|
-
header = self.class.attributes
|
35
|
-
.fetch(view_name, self.class.attributes.fetch(:base))
|
36
|
-
|
37
|
-
if header.is_a?(Proc)
|
38
|
-
instance_exec(&header)
|
39
|
-
else
|
40
|
-
header
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
module ClassInterface
|
46
|
-
# Define a relation view with a specific header
|
47
|
-
#
|
48
|
-
# With headers defined all the mappers will be inferred automatically
|
49
|
-
#
|
50
|
-
# @example
|
51
|
-
# class Users < ROM::Relation[:sql]
|
52
|
-
# view(:by_name, [:id, :name]) do |name|
|
53
|
-
# where(name: name)
|
54
|
-
# end
|
55
|
-
#
|
56
|
-
# view(:listing, [:id, :name, :email]) do
|
57
|
-
# select(:id, :name, :email).order(:name)
|
58
|
-
# end
|
59
|
-
# end
|
60
|
-
#
|
61
|
-
# @api public
|
62
|
-
def view(*args, &block)
|
63
|
-
if args.size == 1 && block.arity > 0
|
64
|
-
raise ArgumentError, "header must be set as second argument"
|
65
|
-
end
|
66
|
-
|
67
|
-
name, names, relation_block =
|
68
|
-
if args.size == 1
|
69
|
-
DSL.new(*args, &block).call
|
70
|
-
else
|
71
|
-
[*args, block]
|
72
|
-
end
|
73
|
-
|
74
|
-
attributes[name] = names
|
75
|
-
|
76
|
-
if relation_block.arity > 0
|
77
|
-
auto_curry_guard do
|
78
|
-
define_method(name, &relation_block)
|
79
|
-
auto_curry(name) { with(view: name) }
|
80
|
-
end
|
81
|
-
else
|
82
|
-
define_method(name) do
|
83
|
-
instance_exec(&relation_block).with(view: name)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
ROM.plugins do
|
94
|
-
register :view, ROM::Plugins::Relation::View, type: :relation
|
95
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'rom'
|
2
|
-
require 'rom/memory'
|
3
|
-
require 'rom/plugins/relation/view'
|
4
|
-
|
5
|
-
RSpec.describe ROM::Plugins::Relation::View do
|
6
|
-
subject(:relation) { relation_class.new([]) }
|
7
|
-
|
8
|
-
let(:relation_class) do
|
9
|
-
Class.new(ROM::Memory::Relation) do
|
10
|
-
use :view
|
11
|
-
|
12
|
-
view(:base, [:id, :name]) do
|
13
|
-
self
|
14
|
-
end
|
15
|
-
|
16
|
-
view(:ids, [:id]) do
|
17
|
-
self
|
18
|
-
end
|
19
|
-
|
20
|
-
view(:names, [:name]) do |id|
|
21
|
-
self
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe '#attributes' do
|
27
|
-
it 'returns base view attributes by default' do
|
28
|
-
expect(relation.attributes).to eql([:id, :name])
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'returns attributes for a view' do
|
32
|
-
expect(relation.ids.attributes).to eql([:id])
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'returns attributes for a view with args' do
|
36
|
-
expect(relation.names(1).attributes).to eql([:name])
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'returns attributes for a curried view' do
|
40
|
-
expect(relation.names.attributes).to eql([:name])
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'returns correct arity for a curried view' do
|
44
|
-
expect(relation.names.arity).to be(1)
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'returns explicitly set attributes' do
|
48
|
-
expect(relation.with(attributes: [:foo, :bar]).attributes).to eql([:foo, :bar])
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|