mongoid 7.2.2 → 7.2.6
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +1 -1
- data/lib/config/locales/en.yml +13 -0
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +1 -1
- data/lib/mongoid/association/proxy.rb +1 -1
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +1 -1
- data/lib/mongoid/association/referenced/has_many/proxy.rb +1 -1
- data/lib/mongoid/association/relatable.rb +2 -0
- data/lib/mongoid/config/environment.rb +9 -1
- data/lib/mongoid/contextual/atomic.rb +7 -2
- data/lib/mongoid/contextual/none.rb +3 -0
- data/lib/mongoid/criteria/queryable/selectable.rb +2 -2
- data/lib/mongoid/criteria/queryable/storable.rb +4 -4
- data/lib/mongoid/criteria.rb +1 -1
- data/lib/mongoid/document.rb +3 -2
- data/lib/mongoid/errors/empty_config_file.rb +26 -0
- data/lib/mongoid/errors/invalid_config_file.rb +26 -0
- data/lib/mongoid/errors/mongoid_error.rb +1 -1
- data/lib/mongoid/errors.rb +2 -0
- data/lib/mongoid/interceptable.rb +1 -1
- data/lib/mongoid/persistence_context.rb +3 -1
- data/lib/mongoid/query_cache.rb +11 -1
- data/lib/mongoid/tasks/database.rb +1 -1
- data/lib/mongoid/validatable/associated.rb +1 -1
- data/lib/mongoid/validatable/presence.rb +3 -3
- data/lib/mongoid/validatable/uniqueness.rb +1 -1
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid.rb +1 -0
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +1 -1
- data/spec/integration/app_spec.rb +3 -0
- data/spec/integration/contextual/empty_spec.rb +142 -0
- data/spec/integration/stringified_symbol_field_spec.rb +2 -2
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +17 -4
- data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +17 -0
- data/spec/mongoid/association/referenced/belongs_to_query_spec.rb +20 -0
- data/spec/mongoid/association/referenced/has_many_models.rb +17 -0
- data/spec/mongoid/clients/factory_spec.rb +9 -3
- data/spec/mongoid/clients/options_spec.rb +11 -3
- data/spec/mongoid/config/environment_spec.rb +86 -8
- data/spec/mongoid/contextual/atomic_spec.rb +64 -25
- data/spec/mongoid/contextual/geo_near_spec.rb +1 -1
- data/spec/mongoid/criteria_spec.rb +4 -0
- data/spec/mongoid/document_fields_spec.rb +26 -0
- data/spec/mongoid/document_query_spec.rb +51 -0
- data/spec/mongoid/document_spec.rb +21 -1
- data/spec/mongoid/errors/invalid_config_file_spec.rb +32 -0
- data/spec/mongoid/errors/mongoid_error_spec.rb +20 -8
- data/spec/mongoid/persistable/updatable_spec.rb +2 -0
- data/spec/mongoid/persistable_spec.rb +2 -2
- data/spec/mongoid/query_cache_spec.rb +24 -0
- data/spec/shared/bin/s3-copy +45 -0
- data/spec/shared/bin/s3-upload +69 -0
- data/spec/shared/lib/mrss/cluster_config.rb +8 -3
- data/spec/shared/lib/mrss/constraints.rb +49 -10
- data/spec/shared/lib/mrss/docker_runner.rb +7 -1
- data/spec/shared/lib/mrss/event_subscriber.rb +200 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +17 -12
- data/spec/shared/lib/mrss/spec_organizer.rb +29 -2
- data/spec/shared/share/Dockerfile.erb +127 -35
- data/spec/shared/share/haproxy-1.conf +16 -0
- data/spec/shared/share/haproxy-2.conf +17 -0
- data/spec/shared/shlib/server.sh +100 -23
- data/spec/shared/shlib/set_env.sh +4 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/support/models/address.rb +4 -0
- data/spec/support/models/mop.rb +10 -0
- data/spec/support/models/person.rb +9 -0
- data.tar.gz.sig +0 -0
- metadata +549 -519
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e421b4ac00142136b0a04a14e31c432c95d6fc040dd54a606b4a26f5028ef04e
|
4
|
+
data.tar.gz: cb252a745ffcf28e5da18a2f6d8007be05403af3c81d3f35307608acc19c99b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ad32c694837c1ebb182f7082b084b57680d20f47306745f2c58c9af7eab41058acfa877e73e25d731bdb84d103f761ff8aca7fb13d49d7ecd1c846491581f4a
|
7
|
+
data.tar.gz: b8b329017900e2405af3bb183f824ee3bb5e43bca44784ea0a43895c03ce2bb650e9862395f6118bb346dc02dc838fc997b900e9b24e5ce7b1e84f0c81948538
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
data/lib/config/locales/en.yml
CHANGED
@@ -80,6 +80,12 @@ en:
|
|
80
80
|
different collections so a simple id lookup is not sufficient enough."
|
81
81
|
resolution: "Don't attempt to perform this action and have patience,
|
82
82
|
maybe this will be supported in the future."
|
83
|
+
empty_config_file:
|
84
|
+
message: "Empty configuration file: %{path}."
|
85
|
+
summary: "Your mongoid.yml configuration file appears to be empty."
|
86
|
+
resolution: "Ensure your configuration file contains the correct contents.
|
87
|
+
Please consult the following page with respect to Mongoid's configuration:
|
88
|
+
https://docs.mongodb.com/mongoid/current/reference/configuration/"
|
83
89
|
invalid_collection:
|
84
90
|
message: "Access to the collection for %{klass} is not allowed."
|
85
91
|
summary: "%{klass}.collection was called, and %{klass} is an embedded
|
@@ -94,6 +100,13 @@ en:
|
|
94
100
|
A collation option is only supported if the query is executed on a MongoDB server
|
95
101
|
with version >= 3.4."
|
96
102
|
resolution: "Remove the collation option from the query."
|
103
|
+
invalid_config_file:
|
104
|
+
message: "Invalid configuration file: %{path}."
|
105
|
+
summary: "Your mongoid.yml configuration file does not contain the
|
106
|
+
correct file structure."
|
107
|
+
resolution: "Ensure your configuration file contains the correct contents.
|
108
|
+
Please consult the following page with respect to Mongoid's configuration:
|
109
|
+
https://docs.mongodb.com/mongoid/current/reference/configuration/"
|
97
110
|
invalid_config_option:
|
98
111
|
message: "Invalid configuration option: %{name}."
|
99
112
|
summary: "A invalid configuration option was provided in your
|
@@ -415,7 +415,7 @@ module Mongoid
|
|
415
415
|
# @param [ Proc ] block Optional block to pass.
|
416
416
|
#
|
417
417
|
# @return [ Criteria, Object ] A Criteria or return value from the target.
|
418
|
-
def method_missing(name, *args, &block)
|
418
|
+
ruby2_keywords def method_missing(name, *args, &block)
|
419
419
|
return super if _target.respond_to?(name)
|
420
420
|
klass.send(:with_scope, criteria) do
|
421
421
|
criteria.public_send(name, *args, &block)
|
@@ -133,7 +133,7 @@ module Mongoid
|
|
133
133
|
# @param [ String, Symbol ] name The name of the method.
|
134
134
|
# @param [ Array ] args The arguments passed to the method.
|
135
135
|
#
|
136
|
-
def method_missing(name, *args, &block)
|
136
|
+
ruby2_keywords def method_missing(name, *args, &block)
|
137
137
|
_target.send(name, *args, &block)
|
138
138
|
end
|
139
139
|
|
@@ -443,7 +443,7 @@ module Mongoid
|
|
443
443
|
# @return [ Criteria, Object ] A Criteria or return value from the target.
|
444
444
|
#
|
445
445
|
# @since 2.0.0.beta.1
|
446
|
-
def method_missing(name, *args, &block)
|
446
|
+
ruby2_keywords def method_missing(name, *args, &block)
|
447
447
|
if _target.respond_to?(name)
|
448
448
|
_target.send(name, *args, &block)
|
449
449
|
else
|
@@ -52,7 +52,15 @@ module Mongoid
|
|
52
52
|
# @api private
|
53
53
|
def load_yaml(path, environment = nil)
|
54
54
|
env = environment ? environment.to_s : env_name
|
55
|
-
|
55
|
+
contents = File.new(path).read
|
56
|
+
if contents.empty?
|
57
|
+
raise Mongoid::Errors::EmptyConfigFile.new(path)
|
58
|
+
end
|
59
|
+
data = YAML.load(ERB.new(contents).result)
|
60
|
+
unless data.is_a?(Hash)
|
61
|
+
raise Mongoid::Errors::InvalidConfigFile.new(path)
|
62
|
+
end
|
63
|
+
data[env]
|
56
64
|
end
|
57
65
|
end
|
58
66
|
end
|
@@ -173,13 +173,18 @@ module Mongoid
|
|
173
173
|
# @example Unset the field on the matches.
|
174
174
|
# context.unset(:name)
|
175
175
|
#
|
176
|
-
# @param [ String
|
176
|
+
# @param [ String | Symbol | Array<String|Symbol> | Hash ] args
|
177
|
+
# The name(s) of the field(s) to unset.
|
178
|
+
# If a Hash is specified, its keys will be used irrespective of what
|
179
|
+
# each key's value is, even if the value is nil or false.
|
177
180
|
#
|
178
181
|
# @return [ nil ] Nil.
|
179
182
|
#
|
180
183
|
# @since 3.0.0
|
181
184
|
def unset(*args)
|
182
|
-
fields = args.
|
185
|
+
fields = args.map { |a| a.is_a?(Hash) ? a.keys : a }
|
186
|
+
.__find_args__
|
187
|
+
.map { |f| [database_field_name(f), true] }
|
183
188
|
view.update_many("$unset" => Hash[fields])
|
184
189
|
end
|
185
190
|
|
@@ -597,7 +597,7 @@ module Mongoid
|
|
597
597
|
end
|
598
598
|
_mongoid_expand_keys(new_s).each do |k, v|
|
599
599
|
k = k.to_s
|
600
|
-
if c.selector[k] || k
|
600
|
+
if c.selector[k] || k.start_with?('$')
|
601
601
|
c = c.send(:__multi__, [{'$nor' => [{k => v}]}], '$and')
|
602
602
|
else
|
603
603
|
if v.is_a?(Hash)
|
@@ -889,7 +889,7 @@ module Mongoid
|
|
889
889
|
end
|
890
890
|
criterion.each do |field, value|
|
891
891
|
field_s = field.to_s
|
892
|
-
if field_s
|
892
|
+
if field_s.start_with?('$')
|
893
893
|
# Query expression-level operator, like $and or $where
|
894
894
|
query.add_operator_expression(field_s, value)
|
895
895
|
else
|
@@ -38,7 +38,7 @@ module Mongoid
|
|
38
38
|
raise ArgumentError, "Field must be a string: #{field}"
|
39
39
|
end
|
40
40
|
|
41
|
-
if field
|
41
|
+
if field.start_with?('$')
|
42
42
|
raise ArgumentError, "Field cannot be an operator (i.e. begin with $): #{field}"
|
43
43
|
end
|
44
44
|
|
@@ -48,7 +48,7 @@ module Mongoid
|
|
48
48
|
if value.is_a?(Hash) && selector[field].is_a?(Hash) &&
|
49
49
|
value.keys.all? { |key|
|
50
50
|
key_s = key.to_s
|
51
|
-
key_s
|
51
|
+
key_s.start_with?('$') && !selector[field].key?(key_s)
|
52
52
|
}
|
53
53
|
then
|
54
54
|
# Multiple operators can be combined on the same field by
|
@@ -185,7 +185,7 @@ module Mongoid
|
|
185
185
|
raise ArgumentError, "Operator must be a string: #{operator}"
|
186
186
|
end
|
187
187
|
|
188
|
-
unless operator
|
188
|
+
unless operator.start_with?('$')
|
189
189
|
raise ArgumentError, "Operator must begin with $: #{operator}"
|
190
190
|
end
|
191
191
|
|
@@ -220,7 +220,7 @@ module Mongoid
|
|
220
220
|
raise ArgumentError, "Field must be a string: #{field}"
|
221
221
|
end
|
222
222
|
|
223
|
-
if field
|
223
|
+
if field.start_with?('$')
|
224
224
|
add_operator_expression(field, value)
|
225
225
|
else
|
226
226
|
add_field_expression(field, value)
|
data/lib/mongoid/criteria.rb
CHANGED
@@ -568,7 +568,7 @@ module Mongoid
|
|
568
568
|
# @return [ Object ] The result of the method call.
|
569
569
|
#
|
570
570
|
# @since 1.0.0
|
571
|
-
def method_missing(name, *args, &block)
|
571
|
+
ruby2_keywords def method_missing(name, *args, &block)
|
572
572
|
if klass.respond_to?(name)
|
573
573
|
klass.send(:with_scope, self) do
|
574
574
|
klass.send(name, *args, &block)
|
data/lib/mongoid/document.rb
CHANGED
@@ -194,8 +194,8 @@ module Mongoid
|
|
194
194
|
#
|
195
195
|
# @param [ Hash ] options The options.
|
196
196
|
#
|
197
|
-
# @option options [ true, false ] :compact Whether to include fields
|
198
|
-
# nil values in the json document.
|
197
|
+
# @option options [ true, false ] :compact (Deprecated) Whether to include fields
|
198
|
+
# with nil values in the json document.
|
199
199
|
#
|
200
200
|
# @return [ Hash ] The document as json.
|
201
201
|
#
|
@@ -203,6 +203,7 @@ module Mongoid
|
|
203
203
|
def as_json(options = nil)
|
204
204
|
rv = super
|
205
205
|
if options && options[:compact]
|
206
|
+
Mongoid.logger.warn('#as_json :compact option is deprecated. Please call #compact on the returned Hash object instead.')
|
206
207
|
rv = rv.compact
|
207
208
|
end
|
208
209
|
rv
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
module Mongoid
|
5
|
+
module Errors
|
6
|
+
|
7
|
+
# This error is raised when an empty configuration file is attempted to be
|
8
|
+
# loaded.
|
9
|
+
class EmptyConfigFile < MongoidError
|
10
|
+
|
11
|
+
# Create the new error.
|
12
|
+
#
|
13
|
+
# @param [ String ] path The path of the config file used.
|
14
|
+
#
|
15
|
+
# @api private
|
16
|
+
def initialize(path)
|
17
|
+
super(
|
18
|
+
compose_message(
|
19
|
+
"empty_config_file",
|
20
|
+
{ path: path }
|
21
|
+
)
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
module Mongoid
|
5
|
+
module Errors
|
6
|
+
|
7
|
+
# This error is raised when a bad configuration file is attempted to be
|
8
|
+
# loaded.
|
9
|
+
class InvalidConfigFile < MongoidError
|
10
|
+
|
11
|
+
# Create the new error.
|
12
|
+
#
|
13
|
+
# @param [ String ] path The path of the config file used.
|
14
|
+
#
|
15
|
+
# @api private
|
16
|
+
def initialize(path)
|
17
|
+
super(
|
18
|
+
compose_message(
|
19
|
+
"invalid_config_file",
|
20
|
+
{ path: path }
|
21
|
+
)
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/mongoid/errors.rb
CHANGED
@@ -8,8 +8,10 @@ require "mongoid/errors/criteria_argument_required"
|
|
8
8
|
require "mongoid/errors/document_not_destroyed"
|
9
9
|
require "mongoid/errors/document_not_found"
|
10
10
|
require "mongoid/errors/eager_load"
|
11
|
+
require "mongoid/errors/empty_config_file"
|
11
12
|
require "mongoid/errors/in_memory_collation_not_supported"
|
12
13
|
require "mongoid/errors/invalid_collection"
|
14
|
+
require "mongoid/errors/invalid_config_file"
|
13
15
|
require "mongoid/errors/invalid_config_option"
|
14
16
|
require "mongoid/errors/invalid_dependent_strategy"
|
15
17
|
require "mongoid/errors/invalid_field"
|
@@ -125,7 +125,7 @@ module Mongoid
|
|
125
125
|
# @return [ Document ] The document
|
126
126
|
#
|
127
127
|
# @since 2.3.0
|
128
|
-
def run_callbacks(kind, *args, &block)
|
128
|
+
ruby2_keywords def run_callbacks(kind, *args, &block)
|
129
129
|
cascadable_children(kind).each do |child|
|
130
130
|
if child.run_callbacks(child_callback_type(kind, child), *args) == false
|
131
131
|
return false
|
@@ -237,7 +237,9 @@ module Mongoid
|
|
237
237
|
# @since 6.0.0
|
238
238
|
def clear(object, cluster = nil, original_context = nil)
|
239
239
|
if context = get(object)
|
240
|
-
|
240
|
+
unless cluster.nil? || context.cluster.equal?(cluster)
|
241
|
+
context.client.close
|
242
|
+
end
|
241
243
|
end
|
242
244
|
ensure
|
243
245
|
Thread.current["[mongoid][#{object.object_id}]:context"] = original_context
|
data/lib/mongoid/query_cache.rb
CHANGED
@@ -7,8 +7,14 @@ module Mongoid
|
|
7
7
|
#
|
8
8
|
# @since 4.0.0
|
9
9
|
module QueryCache
|
10
|
-
|
10
|
+
# @api private
|
11
|
+
LEGACY_WARNING = <<~DOC
|
12
|
+
You are using the legacy Mongoid query cache which has known issues.
|
13
|
+
Please upgrade the `mongo' gem to at least 2.14.0 to use the improved driver query cache.
|
14
|
+
Refer to: https://docs.mongodb.com/mongoid/current/tutorials/mongoid-queries/#the-improved-driver-query-cache
|
15
|
+
DOC
|
11
16
|
|
17
|
+
class << self
|
12
18
|
# Get the cached queries.
|
13
19
|
#
|
14
20
|
# @example Get the cached queries from the current thread.
|
@@ -86,6 +92,10 @@ module Mongoid
|
|
86
92
|
if defined?(Mongo::QueryCache)
|
87
93
|
Mongo::QueryCache.cache(&block)
|
88
94
|
else
|
95
|
+
@legacy_query_cache_warned ||= begin
|
96
|
+
Mongoid.logger.warn(LEGACY_WARNING)
|
97
|
+
true
|
98
|
+
end
|
89
99
|
enabled = QueryCache.enabled?
|
90
100
|
QueryCache.enabled = true
|
91
101
|
begin
|
@@ -123,7 +123,7 @@ module Mongoid
|
|
123
123
|
next if model.shard_config.nil?
|
124
124
|
|
125
125
|
if model.embedded? && !model.cyclic?
|
126
|
-
logger.warn("MONGOID: #{model} has shard config but is
|
126
|
+
logger.warn("MONGOID: #{model} has shard config but is embedded")
|
127
127
|
next
|
128
128
|
end
|
129
129
|
|
@@ -34,15 +34,15 @@ module Mongoid
|
|
34
34
|
document.errors.add(
|
35
35
|
attribute,
|
36
36
|
:blank_in_locale,
|
37
|
-
options.merge(location: _locale)
|
37
|
+
**options.merge(location: _locale)
|
38
38
|
) if not_present?(_value)
|
39
39
|
end
|
40
40
|
elsif document.relations.has_key?(attribute.to_s)
|
41
41
|
if relation_or_fk_missing?(document, attribute, value)
|
42
|
-
document.errors.add(attribute, :blank, options)
|
42
|
+
document.errors.add(attribute, :blank, **options)
|
43
43
|
end
|
44
44
|
else
|
45
|
-
document.errors.add(attribute, :blank, options) if not_present?(value)
|
45
|
+
document.errors.add(attribute, :blank, **options) if not_present?(value)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -68,7 +68,7 @@ module Mongoid
|
|
68
68
|
# @since 2.4.10
|
69
69
|
def add_error(document, attribute, value)
|
70
70
|
document.errors.add(
|
71
|
-
attribute, :taken, options.except(:case_sensitive, :scope).merge(value: value)
|
71
|
+
attribute, :taken, **options.except(:case_sensitive, :scope).merge(value: value)
|
72
72
|
)
|
73
73
|
end
|
74
74
|
|
data/lib/mongoid/version.rb
CHANGED
data/lib/mongoid.rb
CHANGED
@@ -57,7 +57,7 @@ development:
|
|
57
57
|
# connect: :direct
|
58
58
|
|
59
59
|
# Changes the default time in seconds the server monitors refresh their status
|
60
|
-
# via
|
60
|
+
# via hello commands. (default: 10)
|
61
61
|
# heartbeat_frequency: 10
|
62
62
|
|
63
63
|
# The time in seconds for selecting servers for a near read preference. (default: 0.015)
|