cuprum-collections 0.5.1 → 0.6.0.rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +47 -0
  3. data/lib/cuprum/collections/adaptable/collection.rb +18 -0
  4. data/lib/cuprum/collections/adaptable/command.rb +22 -0
  5. data/lib/cuprum/collections/adaptable/commands/abstract_assign_one.rb +27 -0
  6. data/lib/cuprum/collections/adaptable/commands/abstract_build_one.rb +25 -0
  7. data/lib/cuprum/collections/adaptable/commands/abstract_validate_one.rb +35 -0
  8. data/lib/cuprum/collections/adaptable/commands.rb +15 -0
  9. data/lib/cuprum/collections/adaptable/query.rb +64 -0
  10. data/lib/cuprum/collections/adaptable.rb +13 -0
  11. data/lib/cuprum/collections/adapter.rb +300 -0
  12. data/lib/cuprum/collections/adapters/data_adapter.rb +82 -0
  13. data/lib/cuprum/collections/adapters/entity_adapter.rb +76 -0
  14. data/lib/cuprum/collections/adapters/hash_adapter.rb +48 -0
  15. data/lib/cuprum/collections/adapters.rb +14 -0
  16. data/lib/cuprum/collections/basic/collection.rb +2 -20
  17. data/lib/cuprum/collections/basic/commands/destroy_one.rb +1 -1
  18. data/lib/cuprum/collections/basic/commands/find_many.rb +0 -31
  19. data/lib/cuprum/collections/basic/commands/find_matching.rb +0 -94
  20. data/lib/cuprum/collections/basic/commands/find_one.rb +0 -18
  21. data/lib/cuprum/collections/basic/commands/insert_one.rb +1 -1
  22. data/lib/cuprum/collections/basic/commands/update_one.rb +1 -1
  23. data/lib/cuprum/collections/basic/scopes/criteria_scope.rb +36 -21
  24. data/lib/cuprum/collections/basic.rb +6 -5
  25. data/lib/cuprum/collections/collection.rb +6 -0
  26. data/lib/cuprum/collections/collection_command.rb +1 -1
  27. data/lib/cuprum/collections/commands/abstract_find_many.rb +40 -3
  28. data/lib/cuprum/collections/commands/abstract_find_matching.rb +102 -0
  29. data/lib/cuprum/collections/commands/abstract_find_one.rb +23 -1
  30. data/lib/cuprum/collections/commands/associations/find_many.rb +1 -3
  31. data/lib/cuprum/collections/commands/associations/require_many.rb +1 -1
  32. data/lib/cuprum/collections/commands/find_one_matching.rb +10 -10
  33. data/lib/cuprum/collections/commands/query_command.rb +6 -4
  34. data/lib/cuprum/collections/commands/upsert.rb +0 -2
  35. data/lib/cuprum/collections/constraints/order/attributes_array.rb +5 -4
  36. data/lib/cuprum/collections/constraints/order/attributes_hash.rb +5 -4
  37. data/lib/cuprum/collections/constraints/order/sort_direction.rb +2 -2
  38. data/lib/cuprum/collections/constraints/ordering.rb +11 -9
  39. data/lib/cuprum/collections/constraints/query_hash.rb +2 -2
  40. data/lib/cuprum/collections/errors/abstract_find_error.rb +101 -23
  41. data/lib/cuprum/collections/errors/extra_attributes.rb +3 -3
  42. data/lib/cuprum/collections/errors/failed_validation.rb +3 -3
  43. data/lib/cuprum/collections/errors/missing_default_contract.rb +12 -4
  44. data/lib/cuprum/collections/queries.rb +4 -0
  45. data/lib/cuprum/collections/relation.rb +0 -2
  46. data/lib/cuprum/collections/relations/parameters.rb +120 -68
  47. data/lib/cuprum/collections/repository.rb +71 -6
  48. data/lib/cuprum/collections/rspec/contracts/query_contracts.rb +23 -4
  49. data/lib/cuprum/collections/rspec/contracts/repository_contracts.rb +18 -0
  50. data/lib/cuprum/collections/rspec/contracts/scope_contracts.rb +51 -0
  51. data/lib/cuprum/collections/rspec/contracts/scopes/builder_contracts.rb +10 -0
  52. data/lib/cuprum/collections/rspec/contracts/scopes/composition_contracts.rb +8 -0
  53. data/lib/cuprum/collections/rspec/contracts/scopes/criteria_contracts.rb +18 -366
  54. data/lib/cuprum/collections/rspec/contracts/scopes/logical_contracts.rb +30 -0
  55. data/lib/cuprum/collections/rspec/contracts/scopes.rb +2 -0
  56. data/lib/cuprum/collections/rspec/contracts.rb +2 -10
  57. data/lib/cuprum/collections/rspec/deferred/adapter_examples.rb +1077 -0
  58. data/lib/cuprum/collections/rspec/deferred/collection_examples.rb +27 -7
  59. data/lib/cuprum/collections/rspec/deferred/commands/assign_one_examples.rb +4 -4
  60. data/lib/cuprum/collections/rspec/deferred/commands/build_one_examples.rb +2 -2
  61. data/lib/cuprum/collections/rspec/deferred/commands/destroy_one_examples.rb +2 -2
  62. data/lib/cuprum/collections/rspec/deferred/commands/find_many_examples.rb +5 -5
  63. data/lib/cuprum/collections/rspec/deferred/commands/find_matching_examples.rb +45 -12
  64. data/lib/cuprum/collections/rspec/deferred/commands/find_one_examples.rb +2 -2
  65. data/lib/cuprum/collections/rspec/deferred/commands/insert_one_examples.rb +1 -1
  66. data/lib/cuprum/collections/rspec/deferred/commands/update_one_examples.rb +1 -1
  67. data/lib/cuprum/collections/rspec/deferred/query_examples.rb +930 -0
  68. data/lib/cuprum/collections/rspec/deferred/relation_examples.rb +48 -17
  69. data/lib/cuprum/collections/rspec/deferred/repository_examples.rb +961 -0
  70. data/lib/cuprum/collections/rspec/deferred/scope_examples.rb +598 -0
  71. data/lib/cuprum/collections/rspec/deferred/scopes/all_examples.rb +391 -0
  72. data/lib/cuprum/collections/rspec/deferred/scopes/builder_examples.rb +857 -0
  73. data/lib/cuprum/collections/rspec/deferred/scopes/composition_examples.rb +93 -0
  74. data/lib/cuprum/collections/rspec/deferred/scopes/conjunction_examples.rb +438 -0
  75. data/lib/cuprum/collections/rspec/deferred/scopes/criteria_examples.rb +1941 -0
  76. data/lib/cuprum/collections/rspec/deferred/scopes/disjunction_examples.rb +415 -0
  77. data/lib/cuprum/collections/rspec/deferred/scopes/none_examples.rb +385 -0
  78. data/lib/cuprum/collections/rspec/deferred/scopes/parser_examples.rb +740 -0
  79. data/lib/cuprum/collections/rspec/deferred/scopes.rb +8 -0
  80. data/lib/cuprum/collections/scope.rb +2 -2
  81. data/lib/cuprum/collections/scopes/container.rb +5 -4
  82. data/lib/cuprum/collections/scopes/criteria/parser.rb +24 -48
  83. data/lib/cuprum/collections/scopes/criteria.rb +7 -6
  84. data/lib/cuprum/collections/version.rb +4 -4
  85. data/lib/cuprum/collections.rb +5 -1
  86. metadata +47 -11
  87. data/lib/cuprum/collections/rspec/contracts/association_contracts.rb +0 -2127
  88. data/lib/cuprum/collections/rspec/contracts/basic.rb +0 -11
  89. data/lib/cuprum/collections/rspec/contracts/collection_contracts.rb +0 -387
  90. data/lib/cuprum/collections/rspec/contracts/command_contracts.rb +0 -169
  91. data/lib/cuprum/collections/rspec/contracts/relation_contracts.rb +0 -1264
@@ -98,7 +98,11 @@ module Cuprum::Collections::RSpec::Deferred
98
98
  let(:constructor_options) do
99
99
  super().merge(name:)
100
100
  end
101
- let(:expected) { options[:default_entity_class] || Book }
101
+ let(:expected) do
102
+ value = options[:default_entity_class] || Book
103
+ value = instance_exec(&value) if value.is_a?(Proc)
104
+ value
105
+ end
102
106
 
103
107
  it { expect(subject.entity_class).to be expected }
104
108
 
@@ -119,7 +123,9 @@ module Cuprum::Collections::RSpec::Deferred
119
123
  super().merge(qualified_name:)
120
124
  end
121
125
  let(:expected) do
122
- options[:default_entity_class] || Spec::ScopedBook
126
+ value = options[:default_entity_class] || Spec::ScopedBook
127
+ value = instance_exec(&value) if value.is_a?(Proc)
128
+ value
123
129
  end
124
130
 
125
131
  it { expect(subject.entity_class).to be expected }
@@ -142,7 +148,11 @@ module Cuprum::Collections::RSpec::Deferred
142
148
  let(:constructor_options) do
143
149
  super().merge(name:)
144
150
  end
145
- let(:expected) { options[:default_entity_class] || Book }
151
+ let(:expected) do
152
+ value = options[:default_entity_class] || Book
153
+ value = instance_exec(&value) if value.is_a?(Proc)
154
+ value
155
+ end
146
156
 
147
157
  it { expect(subject.entity_class).to be expected }
148
158
 
@@ -163,7 +173,9 @@ module Cuprum::Collections::RSpec::Deferred
163
173
  super().merge(qualified_name:)
164
174
  end
165
175
  let(:expected) do
166
- options[:default_entity_class] || Spec::ScopedBook
176
+ value = options[:default_entity_class] || Spec::ScopedBook
177
+ value = instance_exec(&value) if value.is_a?(Proc)
178
+ value
167
179
  end
168
180
 
169
181
  it { expect(subject.entity_class).to be expected }
@@ -187,7 +199,9 @@ module Cuprum::Collections::RSpec::Deferred
187
199
  super().merge(qualified_name:)
188
200
  end
189
201
  let(:expected) do
190
- options[:default_entity_class] || Spec::ScopedBook
202
+ value = options[:default_entity_class] || Spec::ScopedBook
203
+ value = instance_exec(&value) if value.is_a?(Proc)
204
+ value
191
205
  end
192
206
 
193
207
  it { expect(subject.entity_class).to be expected }
@@ -210,7 +224,9 @@ module Cuprum::Collections::RSpec::Deferred
210
224
  super().merge(qualified_name:)
211
225
  end
212
226
  let(:expected) do
213
- options[:default_entity_class] || Spec::ScopedBook
227
+ value = options[:default_entity_class] || Spec::ScopedBook
228
+ value = instance_exec(&value) if value.is_a?(Proc)
229
+ value
214
230
  end
215
231
 
216
232
  it { expect(subject.entity_class).to be expected }
@@ -331,7 +347,15 @@ module Cuprum::Collections::RSpec::Deferred
331
347
  end
332
348
 
333
349
  describe '#options' do
334
- include_examples 'should define reader', :options, -> { {} }
350
+ let(:expected_options) do
351
+ next super() if defined?(super())
352
+
353
+ {}
354
+ end
355
+
356
+ include_examples 'should define reader',
357
+ :options,
358
+ -> { expected_options }
335
359
 
336
360
  context 'when initialized with entity_class: value' do
337
361
  let(:entity_class) { Grimoire }
@@ -341,7 +365,7 @@ module Cuprum::Collections::RSpec::Deferred
341
365
  .merge(entity_class:)
342
366
  end
343
367
 
344
- it { expect(subject.options).to be == {} }
368
+ it { expect(subject.options).to be == expected_options }
345
369
  end
346
370
 
347
371
  context 'when initialized with singular_name: value' do
@@ -350,7 +374,7 @@ module Cuprum::Collections::RSpec::Deferred
350
374
  super().merge(singular_name:)
351
375
  end
352
376
 
353
- it { expect(subject.options).to be == {} }
377
+ it { expect(subject.options).to be == expected_options }
354
378
  end
355
379
 
356
380
  context 'when initialized with name: value' do
@@ -359,7 +383,7 @@ module Cuprum::Collections::RSpec::Deferred
359
383
  super().merge(name:)
360
384
  end
361
385
 
362
- it { expect(subject.options).to be == {} }
386
+ it { expect(subject.options).to be == expected_options }
363
387
  end
364
388
 
365
389
  context 'when initialized with qualified_name: value' do
@@ -368,7 +392,7 @@ module Cuprum::Collections::RSpec::Deferred
368
392
  super().merge(qualified_name:)
369
393
  end
370
394
 
371
- it { expect(subject.options).to be == {} }
395
+ it { expect(subject.options).to be == expected_options }
372
396
  end
373
397
  end
374
398
 
@@ -898,15 +922,22 @@ module Cuprum::Collections::RSpec::Deferred
898
922
 
899
923
  deferred_examples 'should define Relation options' do
900
924
  describe '#options' do
901
- include_examples 'should define reader', :options, -> { {} }
925
+ let(:expected_options) do
926
+ next super() if defined?(super())
927
+
928
+ {}
929
+ end
930
+
931
+ include_examples 'should define reader',
932
+ :options,
933
+ -> { expected_options }
902
934
 
903
935
  context 'when initialized with options' do
904
- let(:options) { { custom_option: 'custom value' } }
905
- let(:constructor_options) do
906
- super().merge(options)
907
- end
936
+ let(:options) { { custom_option: 'custom value' } }
937
+ let(:expected_options) { super().merge(options) }
938
+ let(:constructor_options) { super().merge(options) }
908
939
 
909
- it { expect(subject.options).to be == options }
940
+ it { expect(subject.options).to be == expected_options }
910
941
  end
911
942
  end
912
943
  end