rom 0.9.1 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +30 -12
  3. data/.travis.yml +1 -1
  4. data/CHANGELOG.md +24 -0
  5. data/Gemfile +7 -3
  6. data/README.md +24 -11
  7. data/lib/rom.rb +9 -26
  8. data/lib/rom/command.rb +113 -75
  9. data/lib/rom/commands/class_interface.rb +115 -0
  10. data/lib/rom/commands/graph.rb +17 -23
  11. data/lib/rom/commands/graph/builder.rb +176 -0
  12. data/lib/rom/commands/graph/class_interface.rb +8 -2
  13. data/lib/rom/commands/graph/input_evaluator.rb +13 -9
  14. data/lib/rom/commands/lazy.rb +23 -17
  15. data/lib/rom/commands/lazy/create.rb +23 -0
  16. data/lib/rom/commands/lazy/delete.rb +27 -0
  17. data/lib/rom/commands/lazy/update.rb +34 -0
  18. data/lib/rom/commands/result.rb +14 -0
  19. data/lib/rom/commands/update.rb +0 -4
  20. data/lib/rom/configuration.rb +86 -0
  21. data/lib/rom/{setup_dsl/setup.rb → configuration_dsl.rb} +9 -7
  22. data/lib/rom/configuration_dsl/command.rb +43 -0
  23. data/lib/rom/{setup_dsl → configuration_dsl}/command_dsl.rb +5 -4
  24. data/lib/rom/configuration_dsl/mapper.rb +37 -0
  25. data/lib/rom/{setup_dsl → configuration_dsl}/mapper_dsl.rb +11 -5
  26. data/lib/rom/configuration_dsl/relation.rb +26 -0
  27. data/lib/rom/configuration_plugin.rb +17 -0
  28. data/lib/rom/constants.rb +5 -12
  29. data/lib/rom/container.rb +11 -8
  30. data/lib/rom/create_container.rb +61 -0
  31. data/lib/rom/environment.rb +27 -241
  32. data/lib/rom/gateway.rb +18 -2
  33. data/lib/rom/global.rb +24 -0
  34. data/lib/rom/global/plugin_dsl.rb +2 -0
  35. data/lib/rom/lint/spec.rb +0 -12
  36. data/lib/rom/lint/test.rb +0 -31
  37. data/lib/rom/memory/commands.rb +2 -2
  38. data/lib/rom/memory/gateway.rb +2 -0
  39. data/lib/rom/pipeline.rb +1 -1
  40. data/lib/rom/plugin_base.rb +1 -1
  41. data/lib/rom/plugin_registry.rb +12 -10
  42. data/lib/rom/plugins/configuration/configuration_dsl.rb +16 -0
  43. data/lib/rom/plugins/relation/key_inference.rb +31 -0
  44. data/lib/rom/plugins/relation/view.rb +90 -0
  45. data/lib/rom/plugins/relation/view/dsl.rb +32 -0
  46. data/lib/rom/relation.rb +1 -11
  47. data/lib/rom/relation/class_interface.rb +37 -50
  48. data/lib/rom/setup.rb +13 -104
  49. data/lib/rom/setup/auto_registration.rb +55 -0
  50. data/lib/rom/setup/finalize.rb +113 -127
  51. data/lib/rom/setup/finalize/commands.rb +67 -0
  52. data/lib/rom/setup/finalize/mappers.rb +36 -0
  53. data/lib/rom/setup/finalize/relations.rb +53 -0
  54. data/lib/rom/support/configurable.rb +21 -7
  55. data/lib/rom/version.rb +1 -1
  56. data/rakelib/mutant.rake +4 -1
  57. data/rom.gemspec +3 -4
  58. data/spec/fixtures/app/commands/create_user.rb +2 -0
  59. data/spec/fixtures/app/mappers/user_list.rb +2 -0
  60. data/spec/fixtures/app/relations/users.rb +2 -0
  61. data/spec/fixtures/lib/persistence/commands/create_user.rb +6 -0
  62. data/spec/fixtures/lib/persistence/mappers/user_list.rb +6 -0
  63. data/spec/fixtures/lib/persistence/relations/users.rb +6 -0
  64. data/spec/{unit/rom → integration}/command_registry_spec.rb +8 -9
  65. data/spec/integration/commands/create_spec.rb +17 -13
  66. data/spec/integration/commands/delete_spec.rb +12 -11
  67. data/spec/integration/commands/error_handling_spec.rb +5 -4
  68. data/spec/integration/commands/graph_builder_spec.rb +213 -0
  69. data/spec/integration/commands/graph_spec.rb +112 -49
  70. data/spec/integration/commands/update_spec.rb +14 -11
  71. data/spec/integration/commands_spec.rb +60 -0
  72. data/spec/integration/mappers/combine_spec.rb +7 -6
  73. data/spec/integration/mappers/deep_embedded_spec.rb +5 -6
  74. data/spec/integration/mappers/definition_dsl_spec.rb +19 -18
  75. data/spec/integration/mappers/embedded_spec.rb +11 -12
  76. data/spec/integration/mappers/exclude_spec.rb +5 -6
  77. data/spec/integration/mappers/fold_spec.rb +8 -7
  78. data/spec/integration/mappers/group_spec.rb +16 -15
  79. data/spec/integration/mappers/overwrite_attributes_value_spec.rb +5 -5
  80. data/spec/integration/mappers/prefix_separator_spec.rb +5 -7
  81. data/spec/integration/mappers/prefix_spec.rb +5 -7
  82. data/spec/integration/mappers/prefixing_attributes_spec.rb +7 -7
  83. data/spec/integration/mappers/registering_custom_mappers_spec.rb +4 -5
  84. data/spec/integration/mappers/renaming_attributes_spec.rb +18 -18
  85. data/spec/integration/mappers/step_spec.rb +11 -12
  86. data/spec/integration/mappers/symbolizing_attributes_spec.rb +11 -8
  87. data/spec/integration/mappers/unfold_spec.rb +9 -10
  88. data/spec/integration/mappers/ungroup_spec.rb +10 -11
  89. data/spec/integration/mappers/unwrap_spec.rb +10 -15
  90. data/spec/integration/mappers/wrap_spec.rb +16 -15
  91. data/spec/{unit/rom → integration}/memory/commands/create_spec.rb +7 -5
  92. data/spec/{unit/rom → integration}/memory/commands/delete_spec.rb +7 -5
  93. data/spec/{unit/rom → integration}/memory/commands/update_spec.rb +7 -5
  94. data/spec/integration/multi_env_spec.rb +16 -124
  95. data/spec/integration/multi_repo_spec.rb +9 -9
  96. data/spec/integration/relations/default_dataset_spec.rb +15 -0
  97. data/spec/integration/relations/inheritance_spec.rb +5 -7
  98. data/spec/integration/relations/reading_spec.rb +32 -65
  99. data/spec/integration/relations/registry_dsl_spec.rb +5 -4
  100. data/spec/integration/repositories/extending_relations_spec.rb +6 -7
  101. data/spec/integration/repositories/setting_logger_spec.rb +5 -7
  102. data/spec/integration/setup_spec.rb +49 -61
  103. data/spec/shared/command_graph.rb +50 -0
  104. data/spec/shared/container.rb +9 -0
  105. data/spec/shared/gateway_only.rb +6 -0
  106. data/spec/shared/no_container.rb +16 -0
  107. data/spec/shared/one_behavior.rb +4 -4
  108. data/spec/shared/users_and_tasks.rb +5 -17
  109. data/spec/spec_helper.rb +5 -3
  110. data/spec/test/memory_repository_lint_test.rb +1 -1
  111. data/spec/unit/rom/auto_registration_spec.rb +54 -0
  112. data/spec/unit/rom/commands/graph_spec.rb +18 -44
  113. data/spec/unit/rom/commands/lazy_spec.rb +246 -35
  114. data/spec/unit/rom/commands/result_spec.rb +56 -0
  115. data/spec/unit/rom/commands_spec.rb +9 -73
  116. data/spec/unit/rom/configurable_spec.rb +49 -0
  117. data/spec/unit/rom/configuration_spec.rb +61 -0
  118. data/spec/unit/rom/container_spec.rb +39 -33
  119. data/spec/unit/rom/create_container_spec.rb +151 -0
  120. data/spec/unit/rom/environment_spec.rb +123 -0
  121. data/spec/unit/rom/gateway_spec.rb +58 -2
  122. data/spec/unit/rom/global_spec.rb +10 -7
  123. data/spec/unit/rom/plugin_spec.rb +44 -25
  124. data/spec/unit/rom/plugins/relation/key_inference_spec.rb +27 -0
  125. data/spec/unit/rom/plugins/relation/view_spec.rb +47 -0
  126. data/spec/unit/rom/relation/composite_spec.rb +20 -20
  127. data/spec/unit/rom/relation/curried_spec.rb +10 -11
  128. data/spec/unit/rom/relation/graph_spec.rb +27 -27
  129. data/spec/unit/rom/relation/lazy/combine_spec.rb +26 -20
  130. data/spec/unit/rom/relation/lazy_spec.rb +38 -38
  131. data/spec/unit/rom/relation/loaded_spec.rb +2 -3
  132. data/spec/unit/rom/relation_spec.rb +39 -2
  133. metadata +58 -66
  134. data/lib/rom/commands/abstract.rb +0 -184
  135. data/lib/rom/environment_plugin.rb +0 -17
  136. data/lib/rom/environment_plugins/auto_registration.rb +0 -38
  137. data/lib/rom/repository.rb +0 -16
  138. data/lib/rom/setup_dsl/command.rb +0 -36
  139. data/lib/rom/setup_dsl/mapper.rb +0 -32
  140. data/lib/rom/setup_dsl/relation.rb +0 -30
  141. data/spec/integration/inline_setup_spec.rb +0 -65
  142. data/spec/unit/rom/repository_spec.rb +0 -12
  143. data/spec/unit/rom/setup_spec.rb +0 -253
@@ -1,11 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ROM::Relation::Loaded do
4
+ include_context 'no container'
4
5
  include_context 'users and tasks'
5
6
 
6
- subject(:users) { ROM::Relation::Loaded.new(rom.relations.users) }
7
-
8
- before { setup.relation(:users) }
7
+ subject(:users) { ROM::Relation::Loaded.new(users_relation) }
9
8
 
10
9
  describe '#each' do
11
10
  it 'yields tuples from relation' do
@@ -12,6 +12,16 @@ describe ROM::Relation do
12
12
  describe '.[]' do
13
13
  before do
14
14
  module Test::TestAdapter
15
+ class Relation < ROM::Relation
16
+ adapter :test
17
+
18
+ def test_relation?
19
+ true
20
+ end
21
+ end
22
+ end
23
+
24
+ module Test::BrokenAdapter
15
25
  class Relation < ROM::Relation
16
26
  def test_relation?
17
27
  true
@@ -20,13 +30,30 @@ describe ROM::Relation do
20
30
  end
21
31
 
22
32
  ROM.register_adapter(:test, Test::TestAdapter)
33
+ ROM.register_adapter(:broken, Test::BrokenAdapter)
23
34
  end
24
35
 
25
36
  it 'returns relation subclass from the registered adapter' do
26
- relation = ROM::Relation[:test].new([])
37
+ subclass = Class.new(ROM::Relation[:test])
38
+
39
+ relation = subclass.new([])
27
40
 
28
41
  expect(relation).to be_test_relation
29
42
  end
43
+
44
+ it 'raises error when adapter relation has no identifier' do
45
+ expect {
46
+ Class.new(ROM::Relation[:broken])
47
+ }.to raise_error(ROM::MissingAdapterIdentifierError, /Test::BrokenAdapter::Relation/)
48
+ end
49
+ end
50
+
51
+ describe ".dataset" do
52
+ it 'allows setting dataset name' do
53
+ rel_class = Class.new(ROM::Relation[:memory]) { dataset :users }
54
+
55
+ expect(rel_class.dataset).to be(:users)
56
+ end
30
57
  end
31
58
 
32
59
  describe ".register_as" do
@@ -54,7 +81,7 @@ describe ROM::Relation do
54
81
  dataset :users
55
82
  end
56
83
 
57
- class Test::DescendantUsers < Test::SuperUsers;end
84
+ class Test::DescendantUsers < Test::SuperUsers; end
58
85
 
59
86
  expect(Test::DescendantUsers.register_as).to eq(:test_descendant_users)
60
87
  end
@@ -153,4 +180,14 @@ describe ROM::Relation do
153
180
  expect(relation.to_a).to eql([jane, joe])
154
181
  end
155
182
  end
183
+
184
+ describe "#with" do
185
+ it "returns a new instance with the original dataset and given custom options" do
186
+ custom_opts = { mappers: "Custom Mapper Registry" }
187
+ new_relation = relation.with(custom_opts)
188
+
189
+ expect(new_relation.dataset).to be(relation.dataset)
190
+ expect(new_relation.options).to include(custom_opts)
191
+ end
192
+ end
156
193
  end
metadata CHANGED
@@ -1,95 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 1.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: 2015-08-21 00:00:00.000000000 Z
11
+ date: 2015-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: transproc
14
+ name: dry-equalizer
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.3'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 0.3.0
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '0.3'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 0.3.0
33
- - !ruby/object:Gem::Dependency
34
- name: equalizer
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '0.0'
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- version: 0.0.9
19
+ version: '0.2'
43
20
  type: :runtime
44
21
  prerelease: false
45
22
  version_requirements: !ruby/object:Gem::Requirement
46
23
  requirements:
47
24
  - - "~>"
48
25
  - !ruby/object:Gem::Version
49
- version: '0.0'
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- version: 0.0.9
26
+ version: '0.2'
53
27
  - !ruby/object:Gem::Dependency
54
28
  name: rom-support
55
29
  requirement: !ruby/object:Gem::Requirement
56
30
  requirements:
57
31
  - - "~>"
58
32
  - !ruby/object:Gem::Version
59
- version: '0.1'
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: 0.1.0
33
+ version: 1.0.0.beta1
63
34
  type: :runtime
64
35
  prerelease: false
65
36
  version_requirements: !ruby/object:Gem::Requirement
66
37
  requirements:
67
38
  - - "~>"
68
39
  - !ruby/object:Gem::Version
69
- version: '0.1'
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- version: 0.1.0
40
+ version: 1.0.0.beta1
73
41
  - !ruby/object:Gem::Dependency
74
42
  name: rom-mapper
75
43
  requirement: !ruby/object:Gem::Requirement
76
44
  requirements:
77
45
  - - "~>"
78
46
  - !ruby/object:Gem::Version
79
- version: '0.2'
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: 0.2.0
47
+ version: 0.3.0.beta1
83
48
  type: :runtime
84
49
  prerelease: false
85
50
  version_requirements: !ruby/object:Gem::Requirement
86
51
  requirements:
87
52
  - - "~>"
88
53
  - !ruby/object:Gem::Version
89
- version: '0.2'
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- version: 0.2.0
54
+ version: 0.3.0.beta1
93
55
  - !ruby/object:Gem::Dependency
94
56
  name: rake
95
57
  requirement: !ruby/object:Gem::Requirement
@@ -141,21 +103,32 @@ files:
141
103
  - lib/rom/command.rb
142
104
  - lib/rom/command_registry.rb
143
105
  - lib/rom/commands.rb
144
- - lib/rom/commands/abstract.rb
106
+ - lib/rom/commands/class_interface.rb
145
107
  - lib/rom/commands/composite.rb
146
108
  - lib/rom/commands/create.rb
147
109
  - lib/rom/commands/delete.rb
148
110
  - lib/rom/commands/graph.rb
111
+ - lib/rom/commands/graph/builder.rb
149
112
  - lib/rom/commands/graph/class_interface.rb
150
113
  - lib/rom/commands/graph/input_evaluator.rb
151
114
  - lib/rom/commands/lazy.rb
115
+ - lib/rom/commands/lazy/create.rb
116
+ - lib/rom/commands/lazy/delete.rb
117
+ - lib/rom/commands/lazy/update.rb
152
118
  - lib/rom/commands/result.rb
153
119
  - lib/rom/commands/update.rb
120
+ - lib/rom/configuration.rb
121
+ - lib/rom/configuration_dsl.rb
122
+ - lib/rom/configuration_dsl/command.rb
123
+ - lib/rom/configuration_dsl/command_dsl.rb
124
+ - lib/rom/configuration_dsl/mapper.rb
125
+ - lib/rom/configuration_dsl/mapper_dsl.rb
126
+ - lib/rom/configuration_dsl/relation.rb
127
+ - lib/rom/configuration_plugin.rb
154
128
  - lib/rom/constants.rb
155
129
  - lib/rom/container.rb
130
+ - lib/rom/create_container.rb
156
131
  - lib/rom/environment.rb
157
- - lib/rom/environment_plugin.rb
158
- - lib/rom/environment_plugins/auto_registration.rb
159
132
  - lib/rom/gateway.rb
160
133
  - lib/rom/global.rb
161
134
  - lib/rom/global/plugin_dsl.rb
@@ -175,7 +148,11 @@ files:
175
148
  - lib/rom/plugin.rb
176
149
  - lib/rom/plugin_base.rb
177
150
  - lib/rom/plugin_registry.rb
151
+ - lib/rom/plugins/configuration/configuration_dsl.rb
152
+ - lib/rom/plugins/relation/key_inference.rb
178
153
  - lib/rom/plugins/relation/registry_reader.rb
154
+ - lib/rom/plugins/relation/view.rb
155
+ - lib/rom/plugins/relation/view/dsl.rb
179
156
  - lib/rom/relation.rb
180
157
  - lib/rom/relation/class_interface.rb
181
158
  - lib/rom/relation/composite.rb
@@ -184,27 +161,32 @@ files:
184
161
  - lib/rom/relation/loaded.rb
185
162
  - lib/rom/relation/materializable.rb
186
163
  - lib/rom/relation_registry.rb
187
- - lib/rom/repository.rb
188
164
  - lib/rom/setup.rb
165
+ - lib/rom/setup/auto_registration.rb
189
166
  - lib/rom/setup/finalize.rb
190
- - lib/rom/setup_dsl/command.rb
191
- - lib/rom/setup_dsl/command_dsl.rb
192
- - lib/rom/setup_dsl/mapper.rb
193
- - lib/rom/setup_dsl/mapper_dsl.rb
194
- - lib/rom/setup_dsl/relation.rb
195
- - lib/rom/setup_dsl/setup.rb
167
+ - lib/rom/setup/finalize/commands.rb
168
+ - lib/rom/setup/finalize/mappers.rb
169
+ - lib/rom/setup/finalize/relations.rb
196
170
  - lib/rom/support/configurable.rb
197
171
  - lib/rom/version.rb
198
172
  - rakelib/benchmark.rake
199
173
  - rakelib/mutant.rake
200
174
  - rakelib/rubocop.rake
201
175
  - rom.gemspec
176
+ - spec/fixtures/app/commands/create_user.rb
177
+ - spec/fixtures/app/mappers/user_list.rb
178
+ - spec/fixtures/app/relations/users.rb
179
+ - spec/fixtures/lib/persistence/commands/create_user.rb
180
+ - spec/fixtures/lib/persistence/mappers/user_list.rb
181
+ - spec/fixtures/lib/persistence/relations/users.rb
182
+ - spec/integration/command_registry_spec.rb
202
183
  - spec/integration/commands/create_spec.rb
203
184
  - spec/integration/commands/delete_spec.rb
204
185
  - spec/integration/commands/error_handling_spec.rb
186
+ - spec/integration/commands/graph_builder_spec.rb
205
187
  - spec/integration/commands/graph_spec.rb
206
188
  - spec/integration/commands/update_spec.rb
207
- - spec/integration/inline_setup_spec.rb
189
+ - spec/integration/commands_spec.rb
208
190
  - spec/integration/mappers/combine_spec.rb
209
191
  - spec/integration/mappers/deep_embedded_spec.rb
210
192
  - spec/integration/mappers/definition_dsl_spec.rb
@@ -225,8 +207,12 @@ files:
225
207
  - spec/integration/mappers/ungroup_spec.rb
226
208
  - spec/integration/mappers/unwrap_spec.rb
227
209
  - spec/integration/mappers/wrap_spec.rb
210
+ - spec/integration/memory/commands/create_spec.rb
211
+ - spec/integration/memory/commands/delete_spec.rb
212
+ - spec/integration/memory/commands/update_spec.rb
228
213
  - spec/integration/multi_env_spec.rb
229
214
  - spec/integration/multi_repo_spec.rb
215
+ - spec/integration/relations/default_dataset_spec.rb
230
216
  - spec/integration/relations/inheritance_spec.rb
231
217
  - spec/integration/relations/reading_spec.rb
232
218
  - spec/integration/relations/registry_dsl_spec.rb
@@ -234,8 +220,12 @@ files:
234
220
  - spec/integration/repositories/setting_logger_spec.rb
235
221
  - spec/integration/setup_spec.rb
236
222
  - spec/shared/command_behavior.rb
223
+ - spec/shared/command_graph.rb
224
+ - spec/shared/container.rb
237
225
  - spec/shared/enumerable_dataset.rb
226
+ - spec/shared/gateway_only.rb
238
227
  - spec/shared/materializable.rb
228
+ - spec/shared/no_container.rb
239
229
  - spec/shared/one_behavior.rb
240
230
  - spec/shared/proxy.rb
241
231
  - spec/shared/users_and_tasks.rb
@@ -243,23 +233,26 @@ files:
243
233
  - spec/support/constant_leak_finder.rb
244
234
  - spec/support/mutant.rb
245
235
  - spec/test/memory_repository_lint_test.rb
246
- - spec/unit/rom/command_registry_spec.rb
236
+ - spec/unit/rom/auto_registration_spec.rb
247
237
  - spec/unit/rom/commands/graph_spec.rb
248
238
  - spec/unit/rom/commands/lazy_spec.rb
249
239
  - spec/unit/rom/commands/result_spec.rb
250
240
  - spec/unit/rom/commands_spec.rb
241
+ - spec/unit/rom/configurable_spec.rb
242
+ - spec/unit/rom/configuration_spec.rb
251
243
  - spec/unit/rom/container_spec.rb
244
+ - spec/unit/rom/create_container_spec.rb
245
+ - spec/unit/rom/environment_spec.rb
252
246
  - spec/unit/rom/gateway_spec.rb
253
247
  - spec/unit/rom/global_spec.rb
254
248
  - spec/unit/rom/mapper_registry_spec.rb
255
- - spec/unit/rom/memory/commands/create_spec.rb
256
- - spec/unit/rom/memory/commands/delete_spec.rb
257
- - spec/unit/rom/memory/commands/update_spec.rb
258
249
  - spec/unit/rom/memory/dataset_spec.rb
259
250
  - spec/unit/rom/memory/relation_spec.rb
260
251
  - spec/unit/rom/memory/repository_spec.rb
261
252
  - spec/unit/rom/memory/storage_spec.rb
262
253
  - spec/unit/rom/plugin_spec.rb
254
+ - spec/unit/rom/plugins/relation/key_inference_spec.rb
255
+ - spec/unit/rom/plugins/relation/view_spec.rb
263
256
  - spec/unit/rom/registry_spec.rb
264
257
  - spec/unit/rom/relation/composite_spec.rb
265
258
  - spec/unit/rom/relation/curried_spec.rb
@@ -268,8 +261,6 @@ files:
268
261
  - spec/unit/rom/relation/lazy_spec.rb
269
262
  - spec/unit/rom/relation/loaded_spec.rb
270
263
  - spec/unit/rom/relation_spec.rb
271
- - spec/unit/rom/repository_spec.rb
272
- - spec/unit/rom/setup_spec.rb
273
264
  homepage: http://rom-rb.org
274
265
  licenses:
275
266
  - MIT
@@ -285,9 +276,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
285
276
  version: '0'
286
277
  required_rubygems_version: !ruby/object:Gem::Requirement
287
278
  requirements:
288
- - - ">="
279
+ - - ">"
289
280
  - !ruby/object:Gem::Version
290
- version: '0'
281
+ version: 1.3.1
291
282
  requirements: []
292
283
  rubyforge_project:
293
284
  rubygems_version: 2.4.5
@@ -295,3 +286,4 @@ signing_key:
295
286
  specification_version: 4
296
287
  summary: Ruby Object Mapper
297
288
  test_files: []
289
+ has_rdoc:
@@ -1,184 +0,0 @@
1
- require 'rom/support/options'
2
- require 'rom/support/deprecations'
3
-
4
- require 'rom/commands/composite'
5
- require 'rom/commands/graph'
6
- require 'rom/commands/lazy'
7
-
8
- module ROM
9
- module Commands
10
- # Abstract command class
11
- #
12
- # Provides a constructor accepting relation with options and basic behavior
13
- # for calling, currying and composing commands.
14
- #
15
- # Typically command subclasses should inherit from specialized
16
- # Create/Update/Delete, not this one.
17
- #
18
- # @abstract
19
- #
20
- # @private
21
- class Abstract
22
- include Options
23
- extend Deprecations
24
-
25
- option :type, allow: [:create, :update, :delete]
26
- option :source, reader: true
27
- option :result, reader: true, allow: [:one, :many]
28
- option :validator, reader: true
29
- option :input, reader: true
30
- option :curry_args, type: Array, reader: true, default: EMPTY_ARRAY
31
-
32
- # @attr_reader [Relation] relation The command's relation
33
- attr_reader :relation
34
-
35
- deprecate :target, :relation,
36
- 'Source relation is now available as `Command#source`'
37
-
38
- # @api private
39
- def initialize(relation, options = EMPTY_HASH)
40
- super
41
- @relation = relation
42
- @source = options[:source] || relation
43
- end
44
-
45
- # Execute the command
46
- #
47
- # @abstract
48
- #
49
- # @return [Array] an array with inserted tuples
50
- #
51
- # @api private
52
- def execute(*)
53
- raise(
54
- NotImplementedError,
55
- "#{self.class}##{__method__} must be implemented"
56
- )
57
- end
58
-
59
- # Call the command and return one or many tuples
60
- #
61
- # @api public
62
- def call(*args)
63
- tuples = execute(*(curry_args + args))
64
-
65
- if one?
66
- tuples.first
67
- else
68
- tuples
69
- end
70
- end
71
- alias_method :[], :call
72
-
73
- # Curry this command with provided args
74
- #
75
- # Curried command can be called without args
76
- #
77
- # @return [Command]
78
- #
79
- # @api public
80
- def curry(*args)
81
- if curry_args.empty? && args.first.is_a?(Graph::InputEvaluator)
82
- Lazy.new(self, args.first)
83
- else
84
- self.class.build(relation, options.merge(curry_args: args))
85
- end
86
- end
87
- alias_method :with, :curry
88
-
89
- # Compose a command with another one
90
- #
91
- # The other one will be called with the result from the first one
92
- #
93
- # @example
94
- #
95
- # command = users.create.curry(name: 'Jane')
96
- # command >>= tasks.create.curry(title: 'Task One')
97
- #
98
- # command.call # creates user, passes it to tasks and creates task
99
- #
100
- # @return [Composite]
101
- #
102
- # @api public
103
- def >>(other)
104
- Composite.new(self, other)
105
- end
106
-
107
- # @api public
108
- def combine(*others)
109
- Graph.new(self, others)
110
- end
111
-
112
- # @api private
113
- def lazy?
114
- false
115
- end
116
-
117
- # @api private
118
- def graph?
119
- false
120
- end
121
-
122
- # @api private
123
- def one?
124
- result.equal?(:one)
125
- end
126
-
127
- # @api private
128
- def many?
129
- result.equal?(:many)
130
- end
131
-
132
- # Assert that tuple count in the relation corresponds to :result
133
- # setting
134
- #
135
- # @raise TupleCountMismatchError
136
- #
137
- # @api private
138
- def assert_tuple_count
139
- if one? && tuple_count > 1
140
- raise TupleCountMismatchError, "#{inspect} expects one tuple"
141
- end
142
- end
143
-
144
- # Return number of tuples in the relation relation
145
- #
146
- # This should be overridden by gateways when `#count` is not available
147
- # in the relation objects
148
- #
149
- # @return [Fixnum]
150
- #
151
- # @api private
152
- def tuple_count
153
- relation.count
154
- end
155
-
156
- # @api private
157
- def respond_to_missing?(name, _include_private = false)
158
- relation.respond_to?(name) || super
159
- end
160
-
161
- # @api private
162
- def new(new_relation)
163
- self.class.build(new_relation, options.merge(source: relation))
164
- end
165
-
166
- private
167
-
168
- # @api private
169
- def method_missing(name, *args, &block)
170
- if relation.respond_to?(name)
171
- response = relation.public_send(name, *args, &block)
172
-
173
- if response.instance_of?(relation.class)
174
- new(response)
175
- else
176
- response
177
- end
178
- else
179
- super
180
- end
181
- end
182
- end
183
- end
184
- end