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.
Files changed (149) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -4
  3. data/CHANGELOG.md +34 -1
  4. data/Gemfile +16 -2
  5. data/Rakefile +7 -2
  6. data/lib/rom/array_dataset.rb +44 -0
  7. data/lib/rom/association_set.rb +11 -5
  8. data/lib/rom/auto_curry.rb +55 -0
  9. data/lib/rom/command.rb +70 -41
  10. data/lib/rom/command_registry.rb +7 -18
  11. data/lib/rom/commands/class_interface.rb +7 -6
  12. data/lib/rom/commands/composite.rb +0 -1
  13. data/lib/rom/commands/graph.rb +7 -15
  14. data/lib/rom/commands/lazy/update.rb +1 -1
  15. data/lib/rom/configuration_dsl/command.rb +6 -8
  16. data/lib/rom/configuration_dsl/mapper.rb +2 -3
  17. data/lib/rom/configuration_dsl/mapper_dsl.rb +0 -1
  18. data/lib/rom/configuration_dsl/relation.rb +4 -4
  19. data/lib/rom/configuration_dsl.rb +0 -4
  20. data/lib/rom/constants.rb +1 -1
  21. data/lib/rom/container.rb +0 -2
  22. data/lib/rom/create_container.rb +0 -2
  23. data/lib/rom/data_proxy.rb +94 -0
  24. data/lib/rom/enumerable_dataset.rb +68 -0
  25. data/lib/rom/gateway.rb +23 -6
  26. data/lib/rom/global/plugin_dsl.rb +0 -2
  27. data/lib/rom/global.rb +0 -2
  28. data/lib/rom/initializer.rb +26 -0
  29. data/lib/rom/lint/gateway.rb +17 -0
  30. data/lib/rom/mapper_registry.rb +1 -1
  31. data/lib/rom/memory/commands.rb +0 -2
  32. data/lib/rom/memory/dataset.rb +1 -2
  33. data/lib/rom/memory/relation.rb +14 -1
  34. data/lib/rom/memory/schema.rb +13 -0
  35. data/lib/rom/plugin_registry.rb +1 -1
  36. data/lib/rom/plugins/configuration/configuration_dsl.rb +6 -2
  37. data/lib/rom/plugins/relation/key_inference.rb +4 -2
  38. data/lib/rom/plugins/relation/registry_reader.rb +5 -1
  39. data/lib/rom/registry.rb +50 -0
  40. data/lib/rom/relation/class_interface.rb +94 -26
  41. data/lib/rom/relation/curried.rb +15 -15
  42. data/lib/rom/relation/view_dsl.rb +31 -0
  43. data/lib/rom/relation.rb +49 -34
  44. data/lib/rom/schema/dsl.rb +7 -9
  45. data/lib/rom/schema/type.rb +115 -0
  46. data/lib/rom/schema.rb +218 -18
  47. data/lib/rom/setup/auto_registration.rb +20 -17
  48. data/lib/rom/setup/auto_registration_strategies/base.rb +8 -3
  49. data/lib/rom/setup/auto_registration_strategies/custom_namespace.rb +4 -3
  50. data/lib/rom/setup/auto_registration_strategies/no_namespace.rb +5 -4
  51. data/lib/rom/setup/auto_registration_strategies/with_namespace.rb +3 -3
  52. data/lib/rom/setup/finalize/finalize_commands.rb +1 -1
  53. data/lib/rom/setup/finalize/finalize_mappers.rb +1 -1
  54. data/lib/rom/setup/finalize/finalize_relations.rb +3 -1
  55. data/lib/rom/setup/finalize.rb +1 -1
  56. data/lib/rom/transaction.rb +24 -0
  57. data/lib/rom/types.rb +9 -1
  58. data/lib/rom/version.rb +1 -1
  59. data/lib/rom.rb +4 -8
  60. data/rom.gemspec +4 -3
  61. data/spec/integration/command_registry_spec.rb +1 -14
  62. data/spec/integration/commands/create_spec.rb +5 -25
  63. data/spec/integration/commands/delete_spec.rb +1 -1
  64. data/spec/integration/commands/error_handling_spec.rb +1 -1
  65. data/spec/integration/commands/graph_spec.rb +20 -14
  66. data/spec/integration/commands/update_spec.rb +4 -27
  67. data/spec/integration/commands_spec.rb +1 -1
  68. data/spec/integration/{repositories → gateways}/extending_relations_spec.rb +1 -1
  69. data/spec/integration/{repositories → gateways}/setting_logger_spec.rb +2 -2
  70. data/spec/integration/mappers/combine_spec.rb +1 -1
  71. data/spec/integration/mappers/deep_embedded_spec.rb +1 -1
  72. data/spec/integration/mappers/definition_dsl_spec.rb +1 -1
  73. data/spec/integration/mappers/embedded_spec.rb +1 -1
  74. data/spec/integration/mappers/exclude_spec.rb +1 -1
  75. data/spec/integration/mappers/fold_spec.rb +1 -1
  76. data/spec/integration/mappers/group_spec.rb +1 -1
  77. data/spec/integration/mappers/overwrite_attributes_value_spec.rb +1 -1
  78. data/spec/integration/mappers/prefix_separator_spec.rb +1 -1
  79. data/spec/integration/mappers/prefix_spec.rb +1 -1
  80. data/spec/integration/mappers/prefixing_attributes_spec.rb +1 -1
  81. data/spec/integration/mappers/registering_custom_mappers_spec.rb +1 -1
  82. data/spec/integration/mappers/renaming_attributes_spec.rb +1 -1
  83. data/spec/integration/mappers/reusing_mappers_spec.rb +1 -1
  84. data/spec/integration/mappers/step_spec.rb +1 -1
  85. data/spec/integration/mappers/symbolizing_attributes_spec.rb +1 -1
  86. data/spec/integration/mappers/unfold_spec.rb +1 -1
  87. data/spec/integration/mappers/ungroup_spec.rb +1 -1
  88. data/spec/integration/mappers/unwrap_spec.rb +2 -2
  89. data/spec/integration/mappers/wrap_spec.rb +1 -1
  90. data/spec/integration/memory/commands/create_spec.rb +1 -1
  91. data/spec/integration/memory/commands/delete_spec.rb +1 -1
  92. data/spec/integration/memory/commands/update_spec.rb +1 -1
  93. data/spec/integration/multi_env_spec.rb +1 -1
  94. data/spec/integration/multi_repo_spec.rb +1 -1
  95. data/spec/integration/relations/default_dataset_spec.rb +1 -1
  96. data/spec/integration/relations/reading_spec.rb +1 -1
  97. data/spec/integration/relations/registry_dsl_spec.rb +1 -1
  98. data/spec/integration/setup_spec.rb +10 -4
  99. data/spec/shared/command_graph.rb +8 -4
  100. data/spec/shared/enumerable_dataset.rb +1 -1
  101. data/spec/spec_helper.rb +7 -9
  102. data/spec/support/schema.rb +14 -0
  103. data/spec/unit/rom/array_dataset_spec.rb +59 -0
  104. data/spec/unit/rom/association_set_spec.rb +4 -0
  105. data/spec/unit/rom/auto_curry_spec.rb +63 -0
  106. data/spec/unit/rom/commands/graph_spec.rb +12 -11
  107. data/spec/unit/rom/commands/lazy_spec.rb +8 -5
  108. data/spec/unit/rom/commands/pre_and_post_processors_spec.rb +269 -0
  109. data/spec/unit/rom/commands/result_spec.rb +1 -1
  110. data/spec/unit/rom/commands_spec.rb +9 -3
  111. data/spec/unit/rom/configuration_spec.rb +1 -1
  112. data/spec/unit/rom/container_spec.rb +11 -5
  113. data/spec/unit/rom/create_container_spec.rb +1 -1
  114. data/spec/unit/rom/enumerable_dataset_spec.rb +15 -0
  115. data/spec/unit/rom/gateway_spec.rb +1 -1
  116. data/spec/unit/rom/mapper_registry_spec.rb +1 -1
  117. data/spec/unit/rom/memory/commands_spec.rb +1 -1
  118. data/spec/unit/rom/memory/dataset_spec.rb +1 -1
  119. data/spec/unit/rom/memory/{repository_spec.rb → gateway_spec.rb} +1 -1
  120. data/spec/unit/rom/memory/inheritance_spec.rb +32 -0
  121. data/spec/unit/rom/memory/relation_spec.rb +15 -3
  122. data/spec/unit/rom/memory/storage_spec.rb +1 -1
  123. data/spec/unit/rom/plugin_spec.rb +1 -1
  124. data/spec/unit/rom/plugins/relation/key_inference_spec.rb +1 -1
  125. data/spec/unit/rom/registry_spec.rb +86 -0
  126. data/spec/unit/rom/relation/attribute_reader_spec.rb +17 -0
  127. data/spec/unit/rom/relation/composite_spec.rb +1 -1
  128. data/spec/unit/rom/relation/graph_spec.rb +1 -1
  129. data/spec/unit/rom/relation/lazy/combine_spec.rb +1 -1
  130. data/spec/unit/rom/relation/lazy_spec.rb +1 -1
  131. data/spec/unit/rom/relation/loaded_spec.rb +1 -1
  132. data/spec/unit/rom/relation/schema_spec.rb +10 -6
  133. data/spec/unit/rom/relation/view_spec.rb +112 -0
  134. data/spec/unit/rom/relation_spec.rb +16 -2
  135. data/spec/unit/rom/schema/accessing_attributes_spec.rb +52 -0
  136. data/spec/unit/rom/schema/exclude_spec.rb +15 -0
  137. data/spec/unit/rom/schema/finalize_spec.rb +59 -0
  138. data/spec/unit/rom/schema/key_predicate_spec.rb +15 -0
  139. data/spec/unit/rom/schema/merge_spec.rb +17 -0
  140. data/spec/unit/rom/schema/prefix_spec.rb +16 -0
  141. data/spec/unit/rom/schema/project_spec.rb +15 -0
  142. data/spec/unit/rom/schema/rename_spec.rb +22 -0
  143. data/spec/unit/rom/schema/type_spec.rb +49 -0
  144. data/spec/unit/rom/schema/wrap_spec.rb +17 -0
  145. data/spec/unit/rom/schema_spec.rb +2 -2
  146. metadata +69 -17
  147. data/lib/rom/plugins/relation/view/dsl.rb +0 -32
  148. data/lib/rom/plugins/relation/view.rb +0 -95
  149. 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: 2.0.2
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: 2016-11-11 00:00:00.000000000 Z
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: rom-support
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.0'
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.0'
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.4.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.4.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.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.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/plugins/relation/view.rb
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/plugins/relation/view_spec.rb
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: '0'
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