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
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cuprum/collections/rspec/deferred'
4
+
5
+ module Cuprum::Collections::RSpec::Deferred
6
+ # Namespace for deferred example groups for validating scopes.
7
+ module Scopes; end
8
+ end
@@ -20,8 +20,8 @@ module Cuprum::Collections
20
20
  # @yield the query block.
21
21
  #
22
22
  # @yieldreturn [Hash] a Hash with String keys.
23
- def initialize(*args, inverted: false, &block)
24
- criteria = self.class.parse(*args, &block)
23
+ def initialize(*, inverted: false, &)
24
+ criteria = self.class.parse(*, &)
25
25
 
26
26
  super(criteria:, inverted:)
27
27
  end
@@ -5,10 +5,11 @@ require 'cuprum/collections/scopes'
5
5
  module Cuprum::Collections::Scopes
6
6
  # Functionality for implementing a scope container.
7
7
  module Container
8
- # @param scopes [Array<Scope>] the scopes wrapped by the scope.
9
- # @param options [Hash] additional options for the scope.
10
- def initialize(scopes:, **options)
11
- super(**options)
8
+ # @overload initialize(scopes:, **options)
9
+ # @param scopes [Array<Scope>] the scopes wrapped by the scope.
10
+ # @param options [Hash] additional options for the scope.
11
+ def initialize(scopes:, **)
12
+ super(**)
12
13
 
13
14
  @scopes = scopes
14
15
  end
@@ -63,63 +63,40 @@ module Cuprum::Collections::Scopes::Criteria
63
63
  end
64
64
  alias ne not_equal
65
65
 
66
+ def not_null
67
+ OperatorExpression.new(
68
+ Cuprum::Collections::Queries::Operators::NOT_NULL,
69
+ nil
70
+ )
71
+ end
72
+
66
73
  def not_one_of(*values)
67
74
  OperatorExpression.new(
68
75
  Cuprum::Collections::Queries::Operators::NOT_ONE_OF,
69
- values.flatten
76
+ flatten_values(values)
70
77
  )
71
78
  end
72
79
 
73
- def one_of(*values)
80
+ def null
74
81
  OperatorExpression.new(
75
- Cuprum::Collections::Queries::Operators::ONE_OF,
76
- values.flatten
82
+ Cuprum::Collections::Queries::Operators::NULL,
83
+ nil
77
84
  )
78
85
  end
79
- end
80
86
 
81
- # @deprecated v0.5.0 Implicit receivers are deprecated. Remove this class
82
- # when removing the functionality.
83
- class ImplicitReceiver
84
- ERROR_MESSAGE =
85
- 'Pass a block with one parameter to #parse: { |scope| { ' \
86
- 'scope.%s: value } }'
87
- private_constant :ERROR_MESSAGE
88
-
89
- OPERATORS = %i[
90
- eq
91
- equal
92
- equals
93
- greater_than
94
- greater_than_or_equal_to
95
- gt
96
- gte
97
- less_than
98
- less_than_or_equal_to
99
- lt
100
- lte
101
- ne
102
- not_equal
103
- not_one_of
104
- one_of
105
- ].freeze
106
- private_constant :OPERATORS
107
-
108
- OPERATORS.each do |operator|
109
- define_method(operator) do |*args, **kwargs, &block|
110
- tools.core_tools.deprecate(
111
- '#parse with implicit receiver',
112
- message: format(ERROR_MESSAGE, operator)
113
- )
114
-
115
- BlockParser.instance.send(operator, *args, **kwargs, &block)
116
- end
87
+ def one_of(*values)
88
+ OperatorExpression.new(
89
+ Cuprum::Collections::Queries::Operators::ONE_OF,
90
+ flatten_values(values)
91
+ )
117
92
  end
118
93
 
119
94
  private
120
95
 
121
- def tools
122
- SleepingKingStudios::Tools::Toolbelt.instance
96
+ def flatten_values(values)
97
+ values
98
+ .map { |item| item.is_a?(Set) ? item.to_a : item }
99
+ .flatten
123
100
  end
124
101
  end
125
102
 
@@ -173,6 +150,8 @@ module Cuprum::Collections::Scopes::Criteria
173
150
  def parse(value = UNKNOWN, &)
174
151
  if block_given? && value != UNKNOWN
175
152
  parse_hash(value) + parse_block(&)
153
+ elsif value.is_a?(Proc)
154
+ parse_block(&value)
176
155
  elsif value == UNKNOWN
177
156
  parse_block(&)
178
157
  else
@@ -229,13 +208,10 @@ module Cuprum::Collections::Scopes::Criteria
229
208
 
230
209
  private
231
210
 
232
- # @deprecated v0.5.0 Implicit receivers are deprecated.
233
211
  def evaluate_block(&block)
234
- receiver = ImplicitReceiver.new
235
-
236
- return receiver.instance_exec(&block) if block.arity.zero?
212
+ return block.call if block.arity.zero?
237
213
 
238
- receiver.instance_exec(BlockParser.instance, &block)
214
+ block.call(BlockParser.instance)
239
215
  end
240
216
  end
241
217
  end
@@ -43,12 +43,13 @@ module Cuprum::Collections::Scopes
43
43
  end
44
44
  end
45
45
 
46
- # @param criteria [Array] the criteria used for filtering query data.
47
- # @param inverted [Boolean] if true, the criteria are inverted and should
48
- # match on any criterion (per DeMorgan's Laws).
49
- # @param options [Hash] additional options for the scope.
50
- def initialize(criteria:, inverted: false, **options)
51
- super(**options)
46
+ # @overload initialize(criteria:, inverted: false, **options)
47
+ # @param criteria [Array] the criteria used for filtering query data.
48
+ # @param inverted [Boolean] if true, the criteria are inverted and should
49
+ # match on any criterion (per DeMorgan's Laws).
50
+ # @param options [Hash] additional options for the scope.
51
+ def initialize(criteria:, inverted: false, **)
52
+ super(**)
52
53
 
53
54
  @criteria = criteria
54
55
  @inverted = inverted
@@ -11,13 +11,13 @@ module Cuprum
11
11
  # Major version.
12
12
  MAJOR = 0
13
13
  # Minor version.
14
- MINOR = 5
14
+ MINOR = 6
15
15
  # Patch version.
16
- PATCH = 1
16
+ PATCH = 0
17
17
  # Prerelease version.
18
- PRERELEASE = nil
18
+ PRERELEASE = :rc
19
19
  # Build metadata.
20
- BUILD = nil
20
+ BUILD = 0
21
21
 
22
22
  class << self
23
23
  # Generates the gem version string from the Version constants.
@@ -6,6 +6,9 @@ require 'cuprum'
6
6
  module Cuprum
7
7
  # A data abstraction layer based on the Cuprum library.
8
8
  module Collections
9
+ autoload :Adaptable, 'cuprum/collections/adaptable'
10
+ autoload :Adapter, 'cuprum/collections/adapter'
11
+ autoload :Adapters, 'cuprum/collections/adapters'
9
12
  autoload :Association, 'cuprum/collections/association'
10
13
  autoload :Associations, 'cuprum/collections/associations'
11
14
  autoload :Basic, 'cuprum/collections/basic'
@@ -13,6 +16,7 @@ module Cuprum
13
16
  autoload :CollectionCommand, 'cuprum/collections/collection_command'
14
17
  autoload :Commands, 'cuprum/collections/commands'
15
18
  autoload :Errors, 'cuprum/collections/errors'
19
+ autoload :Queries, 'cuprum/collections/queries'
16
20
  autoload :Query, 'cuprum/collections/query'
17
21
  autoload :Relation, 'cuprum/collections/relation'
18
22
  autoload :Relations, 'cuprum/collections/relations'
@@ -29,7 +33,7 @@ module Cuprum
29
33
  __dir__.sub(pattern, '')
30
34
  end
31
35
 
32
- # @return [String] The current version of the gem.
36
+ # @return [String] the current version of the gem.
33
37
  def self.version
34
38
  VERSION
35
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cuprum-collections
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0.rc.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob "Merlin" Smith
@@ -15,28 +15,42 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '1.1'
18
+ version: '1.3'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: '1.1'
25
+ version: '1.3'
26
+ - !ruby/object:Gem::Dependency
27
+ name: sleeping_king_studios-tools
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.2'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.2'
26
40
  - !ruby/object:Gem::Dependency
27
41
  name: stannum
28
42
  requirement: !ruby/object:Gem::Requirement
29
43
  requirements:
30
44
  - - "~>"
31
45
  - !ruby/object:Gem::Version
32
- version: '0.3'
46
+ version: '0.4'
33
47
  type: :runtime
34
48
  prerelease: false
35
49
  version_requirements: !ruby/object:Gem::Requirement
36
50
  requirements:
37
51
  - - "~>"
38
52
  - !ruby/object:Gem::Version
39
- version: '0.3'
53
+ version: '0.4'
40
54
  description: An adapter library to provide a consistent interface between data stores.
41
55
  email:
42
56
  - merlin@sleepingkingstudios.com
@@ -51,6 +65,19 @@ files:
51
65
  - README.md
52
66
  - config/locales/en.rb
53
67
  - lib/cuprum/collections.rb
68
+ - lib/cuprum/collections/adaptable.rb
69
+ - lib/cuprum/collections/adaptable/collection.rb
70
+ - lib/cuprum/collections/adaptable/command.rb
71
+ - lib/cuprum/collections/adaptable/commands.rb
72
+ - lib/cuprum/collections/adaptable/commands/abstract_assign_one.rb
73
+ - lib/cuprum/collections/adaptable/commands/abstract_build_one.rb
74
+ - lib/cuprum/collections/adaptable/commands/abstract_validate_one.rb
75
+ - lib/cuprum/collections/adaptable/query.rb
76
+ - lib/cuprum/collections/adapter.rb
77
+ - lib/cuprum/collections/adapters.rb
78
+ - lib/cuprum/collections/adapters/data_adapter.rb
79
+ - lib/cuprum/collections/adapters/entity_adapter.rb
80
+ - lib/cuprum/collections/adapters/hash_adapter.rb
54
81
  - lib/cuprum/collections/association.rb
55
82
  - lib/cuprum/collections/associations.rb
56
83
  - lib/cuprum/collections/associations/belongs_to.rb
@@ -128,12 +155,7 @@ files:
128
155
  - lib/cuprum/collections/resource.rb
129
156
  - lib/cuprum/collections/rspec.rb
130
157
  - lib/cuprum/collections/rspec/contracts.rb
131
- - lib/cuprum/collections/rspec/contracts/association_contracts.rb
132
- - lib/cuprum/collections/rspec/contracts/basic.rb
133
- - lib/cuprum/collections/rspec/contracts/collection_contracts.rb
134
- - lib/cuprum/collections/rspec/contracts/command_contracts.rb
135
158
  - lib/cuprum/collections/rspec/contracts/query_contracts.rb
136
- - lib/cuprum/collections/rspec/contracts/relation_contracts.rb
137
159
  - lib/cuprum/collections/rspec/contracts/repository_contracts.rb
138
160
  - lib/cuprum/collections/rspec/contracts/scope_contracts.rb
139
161
  - lib/cuprum/collections/rspec/contracts/scopes.rb
@@ -142,6 +164,7 @@ files:
142
164
  - lib/cuprum/collections/rspec/contracts/scopes/criteria_contracts.rb
143
165
  - lib/cuprum/collections/rspec/contracts/scopes/logical_contracts.rb
144
166
  - lib/cuprum/collections/rspec/deferred.rb
167
+ - lib/cuprum/collections/rspec/deferred/adapter_examples.rb
145
168
  - lib/cuprum/collections/rspec/deferred/association_examples.rb
146
169
  - lib/cuprum/collections/rspec/deferred/collection_examples.rb
147
170
  - lib/cuprum/collections/rspec/deferred/command_examples.rb
@@ -155,8 +178,20 @@ files:
155
178
  - lib/cuprum/collections/rspec/deferred/commands/insert_one_examples.rb
156
179
  - lib/cuprum/collections/rspec/deferred/commands/update_one_examples.rb
157
180
  - lib/cuprum/collections/rspec/deferred/commands/validate_one_examples.rb
181
+ - lib/cuprum/collections/rspec/deferred/query_examples.rb
158
182
  - lib/cuprum/collections/rspec/deferred/relation_examples.rb
183
+ - lib/cuprum/collections/rspec/deferred/repository_examples.rb
159
184
  - lib/cuprum/collections/rspec/deferred/resource_examples.rb
185
+ - lib/cuprum/collections/rspec/deferred/scope_examples.rb
186
+ - lib/cuprum/collections/rspec/deferred/scopes.rb
187
+ - lib/cuprum/collections/rspec/deferred/scopes/all_examples.rb
188
+ - lib/cuprum/collections/rspec/deferred/scopes/builder_examples.rb
189
+ - lib/cuprum/collections/rspec/deferred/scopes/composition_examples.rb
190
+ - lib/cuprum/collections/rspec/deferred/scopes/conjunction_examples.rb
191
+ - lib/cuprum/collections/rspec/deferred/scopes/criteria_examples.rb
192
+ - lib/cuprum/collections/rspec/deferred/scopes/disjunction_examples.rb
193
+ - lib/cuprum/collections/rspec/deferred/scopes/none_examples.rb
194
+ - lib/cuprum/collections/rspec/deferred/scopes/parser_examples.rb
160
195
  - lib/cuprum/collections/rspec/fixtures.rb
161
196
  - lib/cuprum/collections/scope.rb
162
197
  - lib/cuprum/collections/scopes.rb
@@ -182,6 +217,7 @@ licenses:
182
217
  - MIT
183
218
  metadata:
184
219
  bug_tracker_uri: https://github.com/sleepingkingstudios/cuprum-collections/issues
220
+ homepage_uri: http://sleepingkingstudios.com
185
221
  source_code_uri: https://github.com/sleepingkingstudios/cuprum-collections
186
222
  rubygems_mfa_required: 'true'
187
223
  rdoc_options: []
@@ -191,7 +227,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
191
227
  requirements:
192
228
  - - "~>"
193
229
  - !ruby/object:Gem::Version
194
- version: '3.1'
230
+ version: '3.2'
195
231
  required_rubygems_version: !ruby/object:Gem::Requirement
196
232
  requirements:
197
233
  - - ">="