mongoid 5.4.1 → 6.0.0.beta
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 +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/config/locales/en.yml +23 -16
- data/lib/mongoid.rb +4 -9
- data/lib/mongoid/atomic.rb +1 -1
- data/lib/mongoid/atomic/modifiers.rb +8 -12
- data/lib/mongoid/attributes.rb +9 -11
- data/lib/mongoid/attributes/dynamic.rb +5 -6
- data/lib/mongoid/attributes/nested.rb +1 -1
- data/lib/mongoid/attributes/processing.rb +4 -0
- data/lib/mongoid/attributes/readonly.rb +22 -0
- data/lib/mongoid/cacheable.rb +36 -0
- data/lib/mongoid/changeable.rb +37 -1
- data/lib/mongoid/clients.rb +0 -63
- data/lib/mongoid/clients/factory.rb +0 -2
- data/lib/mongoid/clients/options.rb +54 -249
- data/lib/mongoid/clients/storage_options.rb +1 -69
- data/lib/mongoid/composable.rb +26 -2
- data/lib/mongoid/config.rb +1 -1
- data/lib/mongoid/config/options.rb +1 -1
- data/lib/mongoid/contextual/aggregable/mongo.rb +1 -0
- data/lib/mongoid/contextual/atomic.rb +6 -9
- data/lib/mongoid/contextual/geo_near.rb +2 -3
- data/lib/mongoid/contextual/map_reduce.rb +97 -24
- data/lib/mongoid/contextual/memory.rb +7 -4
- data/lib/mongoid/contextual/mongo.rb +63 -54
- data/lib/mongoid/contextual/none.rb +2 -2
- data/lib/mongoid/copyable.rb +19 -19
- data/lib/mongoid/criteria.rb +5 -4
- data/lib/mongoid/criteria/findable.rb +2 -3
- data/lib/mongoid/criteria/includable.rb +63 -16
- data/lib/mongoid/criteria/marshalable.rb +2 -2
- data/lib/mongoid/criteria/modifiable.rb +17 -1
- data/lib/mongoid/criteria/options.rb +25 -0
- data/lib/mongoid/criteria/queryable.rb +86 -0
- data/lib/mongoid/criteria/queryable/aggregable.rb +120 -0
- data/lib/mongoid/criteria/queryable/extensions.rb +28 -0
- data/lib/mongoid/criteria/queryable/extensions/array.rb +185 -0
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +37 -0
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +34 -0
- data/lib/mongoid/criteria/queryable/extensions/date.rb +63 -0
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +53 -0
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +200 -0
- data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +86 -0
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +90 -0
- data/lib/mongoid/criteria/queryable/extensions/object.rb +206 -0
- data/lib/mongoid/criteria/queryable/extensions/range.rb +70 -0
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +45 -0
- data/lib/mongoid/criteria/queryable/extensions/set.rb +34 -0
- data/lib/mongoid/criteria/queryable/extensions/string.rb +137 -0
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +79 -0
- data/lib/mongoid/criteria/queryable/extensions/time.rb +60 -0
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +54 -0
- data/lib/mongoid/criteria/queryable/forwardable.rb +65 -0
- data/lib/mongoid/criteria/queryable/key.rb +103 -0
- data/lib/mongoid/criteria/queryable/macroable.rb +27 -0
- data/lib/mongoid/criteria/queryable/mergeable.rb +271 -0
- data/lib/mongoid/criteria/queryable/optional.rb +411 -0
- data/lib/mongoid/criteria/queryable/options.rb +136 -0
- data/lib/mongoid/criteria/queryable/pipeline.rb +111 -0
- data/lib/mongoid/criteria/queryable/selectable.rb +662 -0
- data/lib/mongoid/criteria/queryable/selector.rb +196 -0
- data/lib/mongoid/criteria/queryable/smash.rb +103 -0
- data/lib/mongoid/document.rb +9 -23
- data/lib/mongoid/errors.rb +2 -1
- data/lib/mongoid/errors/ambiguous_relationship.rb +1 -1
- data/lib/mongoid/errors/delete_restriction.rb +2 -2
- data/lib/mongoid/errors/invalid_field.rb +2 -2
- data/lib/mongoid/errors/invalid_persistence_option.rb +29 -0
- data/lib/mongoid/errors/invalid_relation.rb +66 -0
- data/lib/mongoid/errors/inverse_not_found.rb +1 -1
- data/lib/mongoid/errors/mongoid_error.rb +1 -1
- data/lib/mongoid/evolvable.rb +1 -1
- data/lib/mongoid/extensions.rb +0 -5
- data/lib/mongoid/extensions/big_decimal.rb +17 -8
- data/lib/mongoid/extensions/date.rb +4 -1
- data/lib/mongoid/extensions/hash.rb +2 -3
- data/lib/mongoid/extensions/object.rb +2 -2
- data/lib/mongoid/extensions/string.rb +4 -3
- data/lib/mongoid/extensions/time.rb +5 -2
- data/lib/mongoid/factory.rb +1 -0
- data/lib/mongoid/fields/foreign_key.rb +2 -2
- data/lib/mongoid/fields/localized.rb +3 -8
- data/lib/mongoid/fields/validators/macro.rb +18 -0
- data/lib/mongoid/findable.rb +3 -3
- data/lib/mongoid/indexable.rb +17 -16
- data/lib/mongoid/indexable/specification.rb +1 -1
- data/lib/mongoid/indexable/validators/options.rb +1 -2
- data/lib/mongoid/interceptable.rb +6 -17
- data/lib/mongoid/loggable.rb +1 -1
- data/lib/mongoid/matchable.rb +3 -10
- data/lib/mongoid/matchable/gt.rb +2 -0
- data/lib/mongoid/matchable/gte.rb +2 -0
- data/lib/mongoid/matchable/lt.rb +2 -0
- data/lib/mongoid/matchable/lte.rb +2 -0
- data/lib/mongoid/persistable.rb +6 -5
- data/lib/mongoid/persistable/creatable.rb +2 -0
- data/lib/mongoid/persistable/deletable.rb +7 -3
- data/lib/mongoid/persistable/settable.rb +3 -16
- data/lib/mongoid/persistable/updatable.rb +10 -12
- data/lib/mongoid/persistence_context.rb +216 -0
- data/lib/mongoid/query_cache.rb +5 -30
- data/lib/mongoid/relations/accessors.rb +6 -2
- data/lib/mongoid/relations/auto_save.rb +12 -4
- data/lib/mongoid/relations/bindings/embedded/in.rb +4 -0
- data/lib/mongoid/relations/bindings/embedded/many.rb +8 -1
- data/lib/mongoid/relations/bindings/embedded/one.rb +10 -0
- data/lib/mongoid/relations/bindings/referenced/many.rb +4 -0
- data/lib/mongoid/relations/builders.rb +2 -2
- data/lib/mongoid/relations/builders/embedded/one.rb +1 -1
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +1 -1
- data/lib/mongoid/relations/conversions.rb +1 -1
- data/lib/mongoid/relations/counter_cache.rb +28 -18
- data/lib/mongoid/relations/eager.rb +19 -7
- data/lib/mongoid/relations/eager/base.rb +5 -5
- data/lib/mongoid/relations/embedded/batchable.rb +9 -33
- data/lib/mongoid/relations/embedded/in.rb +16 -2
- data/lib/mongoid/relations/embedded/many.rb +23 -8
- data/lib/mongoid/relations/embedded/one.rb +17 -2
- data/lib/mongoid/relations/macros.rb +9 -2
- data/lib/mongoid/relations/metadata.rb +3 -3
- data/lib/mongoid/relations/nested_builder.rb +1 -1
- data/lib/mongoid/relations/options.rb +2 -2
- data/lib/mongoid/relations/proxy.rb +2 -33
- data/lib/mongoid/relations/referenced/in.rb +23 -11
- data/lib/mongoid/relations/referenced/many.rb +24 -16
- data/lib/mongoid/relations/referenced/many_to_many.rb +20 -13
- data/lib/mongoid/relations/referenced/one.rb +17 -1
- data/lib/mongoid/relations/reflections.rb +3 -5
- data/lib/mongoid/relations/touchable.rb +1 -1
- data/lib/mongoid/reloadable.rb +1 -1
- data/lib/mongoid/scopable.rb +3 -3
- data/lib/mongoid/serializable.rb +2 -3
- data/lib/mongoid/tasks/database.rb +1 -2
- data/lib/mongoid/threaded.rb +4 -4
- data/lib/mongoid/traversable.rb +1 -1
- data/lib/mongoid/validatable.rb +1 -1
- data/lib/mongoid/validatable/macros.rb +2 -4
- data/lib/mongoid/validatable/uniqueness.rb +1 -2
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +4 -7
- data/spec/app/models/album.rb +5 -1
- data/spec/app/models/artist.rb +21 -0
- data/spec/app/models/band.rb +0 -1
- data/spec/app/models/church.rb +0 -2
- data/spec/app/models/ordered_post.rb +5 -0
- data/spec/app/models/oscar.rb +1 -2
- data/spec/app/models/person.rb +3 -1
- data/spec/app/models/post.rb +0 -1
- data/spec/app/models/princess.rb +2 -0
- data/spec/app/models/record.rb +1 -0
- data/spec/app/models/thing.rb +1 -1
- data/spec/config/mongoid.yml +1 -5
- data/spec/mongoid/atomic/modifiers_spec.rb +17 -17
- data/spec/mongoid/atomic_spec.rb +17 -17
- data/spec/mongoid/attributes/nested_spec.rb +14 -14
- data/spec/mongoid/attributes/readonly_spec.rb +87 -44
- data/spec/mongoid/attributes_spec.rb +63 -0
- data/spec/mongoid/cacheable_spec.rb +112 -0
- data/spec/mongoid/changeable_spec.rb +58 -0
- data/spec/mongoid/clients/factory_spec.rb +3 -11
- data/spec/mongoid/clients/options_spec.rb +378 -96
- data/spec/mongoid/clients_spec.rb +207 -170
- data/spec/mongoid/composable_spec.rb +7 -0
- data/spec/mongoid/config_spec.rb +41 -21
- data/spec/mongoid/contextual/atomic_spec.rb +77 -343
- data/spec/mongoid/contextual/map_reduce_spec.rb +119 -111
- data/spec/mongoid/contextual/memory_spec.rb +56 -316
- data/spec/mongoid/contextual/mongo_spec.rb +104 -378
- data/spec/mongoid/copyable_spec.rb +8 -15
- data/spec/mongoid/criteria/modifiable_spec.rb +239 -7
- data/spec/mongoid/criteria/options_spec.rb +29 -0
- data/spec/mongoid/criteria/queryable/aggregable_spec.rb +370 -0
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +523 -0
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +59 -0
- data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +58 -0
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +213 -0
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +330 -0
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +405 -0
- data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +58 -0
- data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +65 -0
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +327 -0
- data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +65 -0
- data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +77 -0
- data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +108 -0
- data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +309 -0
- data/spec/mongoid/{extensions/origin/regexp_raw_spec.rb → criteria/queryable/extensions/regexp_spec.rb} +21 -20
- data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +39 -0
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +302 -0
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +167 -0
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +376 -0
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +347 -0
- data/spec/mongoid/criteria/queryable/forwardable_spec.rb +87 -0
- data/spec/mongoid/criteria/queryable/key_spec.rb +52 -0
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +49 -0
- data/spec/mongoid/criteria/queryable/optional_spec.rb +1786 -0
- data/spec/mongoid/criteria/queryable/options_spec.rb +360 -0
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +200 -0
- data/spec/mongoid/criteria/queryable/queryable_spec.rb +137 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +4159 -0
- data/spec/mongoid/criteria/queryable/selector_spec.rb +778 -0
- data/spec/mongoid/criteria/queryable/smash_spec.rb +30 -0
- data/spec/mongoid/criteria_spec.rb +45 -63
- data/spec/mongoid/document_spec.rb +21 -88
- data/spec/mongoid/errors/invalid_relation_spec.rb +37 -0
- data/spec/mongoid/errors/mongoid_error_spec.rb +6 -3
- data/spec/mongoid/extensions/big_decimal_spec.rb +320 -18
- data/spec/mongoid/extensions/date_spec.rb +2 -6
- data/spec/mongoid/extensions/date_time_spec.rb +2 -6
- data/spec/mongoid/extensions/float_spec.rb +8 -1
- data/spec/mongoid/extensions/integer_spec.rb +8 -1
- data/spec/mongoid/extensions/object_spec.rb +11 -0
- data/spec/mongoid/extensions/string_spec.rb +21 -0
- data/spec/mongoid/extensions/time_spec.rb +4 -8
- data/spec/mongoid/extensions/time_with_zone_spec.rb +2 -6
- data/spec/mongoid/fields/localized_spec.rb +0 -91
- data/spec/mongoid/findable_spec.rb +46 -1
- data/spec/mongoid/indexable_spec.rb +6 -46
- data/spec/mongoid/interceptable_spec.rb +49 -10
- data/spec/mongoid/matchable/gt_spec.rb +11 -0
- data/spec/mongoid/matchable/gte_spec.rb +10 -0
- data/spec/mongoid/matchable/lt_spec.rb +11 -0
- data/spec/mongoid/matchable/lte_spec.rb +11 -0
- data/spec/mongoid/matchable_spec.rb +1 -51
- data/spec/mongoid/persistable/creatable_spec.rb +2 -2
- data/spec/mongoid/persistable/deletable_spec.rb +1 -1
- data/spec/mongoid/persistable/destroyable_spec.rb +6 -2
- data/spec/mongoid/persistable/savable_spec.rb +30 -30
- data/spec/mongoid/persistable/settable_spec.rb +0 -185
- data/spec/mongoid/persistable/updatable_spec.rb +166 -5
- data/spec/mongoid/persistence_context_spec.rb +654 -0
- data/spec/mongoid/positional_spec.rb +10 -10
- data/spec/mongoid/query_cache_spec.rb +89 -65
- data/spec/mongoid/relations/accessors_spec.rb +1 -1
- data/spec/mongoid/relations/auto_save_spec.rb +39 -6
- data/spec/mongoid/relations/builders_spec.rb +37 -10
- data/spec/mongoid/relations/counter_cache_spec.rb +64 -15
- data/spec/mongoid/relations/cyclic_spec.rb +0 -22
- data/spec/mongoid/relations/embedded/many_spec.rb +9 -41
- data/spec/mongoid/relations/embedded/one_spec.rb +2 -1
- data/spec/mongoid/relations/macros_spec.rb +395 -7
- data/spec/mongoid/relations/proxy_spec.rb +3 -1
- data/spec/mongoid/relations/referenced/in_spec.rb +41 -1
- data/spec/mongoid/relations/referenced/many_spec.rb +6 -29
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +6 -29
- data/spec/mongoid/relations/reflections_spec.rb +9 -9
- data/spec/mongoid/reloadable_spec.rb +51 -0
- data/spec/mongoid/scopable_spec.rb +0 -12
- data/spec/mongoid/serializable_spec.rb +0 -50
- data/spec/mongoid/validatable/presence_spec.rb +1 -1
- data/spec/mongoid/validatable/uniqueness_spec.rb +16 -9
- data/spec/mongoid/validatable_spec.rb +16 -0
- data/spec/spec_helper.rb +10 -10
- metadata +536 -479
- metadata.gz.sig +0 -0
- data/lib/mongoid/clients/thread_options.rb +0 -19
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +0 -20
- data/lib/mongoid/extensions/decimal128.rb +0 -39
- data/lib/mongoid/extensions/origin/regexp_raw.rb +0 -43
- data/lib/mongoid/matchable/regexp.rb +0 -27
- data/spec/app/models/post_genre.rb +0 -6
- data/spec/mongoid/extensions/decimal128_spec.rb +0 -44
- data/spec/mongoid/matchable/regexp_spec.rb +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 57db37f3ffe123d41531a6c93d9ae52e37cb81d2
|
4
|
+
data.tar.gz: bdd70c57cb017f481fa796c8a86dc34599c1a05c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c6b4a55f532af6dfd8c2593bb8bd05244a5916235ed9512487b7d45952e37a06e9eb50f61958d4b63da826d9631ca6422e0febb638da45e122246ead03e1461
|
7
|
+
data.tar.gz: 15cbe1acb92704217bb2f2f084d14c076dce7c6c7aa5afcd6955f724825f2e6e72a89c6e0c62170c4ba4d60d04866052ce041d37ee3ea4f1be8a4d15d38070b9
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/config/locales/en.yml
CHANGED
@@ -76,12 +76,6 @@ en:
|
|
76
76
|
resolution: "For access to the collection that the embedded document is
|
77
77
|
in, use %{klass}#_root.collection, or do not attempt to persist an
|
78
78
|
embedded document without a parent set."
|
79
|
-
in_memory_collation_not_supported:
|
80
|
-
message: "A collation option cannot be applied when querying documents in-memory."
|
81
|
-
summary: "The query being run against documents in memory has a collation option set.
|
82
|
-
A collation option is only supported if the query is executed on a MongoDB server
|
83
|
-
with version >= 3.4."
|
84
|
-
resolution: "Remove the collation option from the query."
|
85
79
|
invalid_config_option:
|
86
80
|
message: "Invalid configuration option: %{name}."
|
87
81
|
summary: "A invalid configuration option was provided in your
|
@@ -121,7 +115,10 @@ en:
|
|
121
115
|
invalid_includes:
|
122
116
|
message: "Invalid includes directive: %{klass}.includes(%{args})"
|
123
117
|
summary: "Eager loading in Mongoid only supports providing arguments
|
124
|
-
to %{klass}.includes that are the names of relations on the %{klass}
|
118
|
+
to %{klass}.includes that are the names of relations on the %{klass}
|
119
|
+
model, and only supports one level of eager loading. (ie, eager loading
|
120
|
+
associations not on the %{klass} but one step away via another relation
|
121
|
+
is not allowed."
|
125
122
|
resolution: "Ensure that each parameter passed to %{klass}.includes is
|
126
123
|
a valid name of a relation on the %{klass} model. These are: %{relations}."
|
127
124
|
invalid_index:
|
@@ -140,18 +137,9 @@ en:
|
|
140
137
|
\_\_min: 1\n
|
141
138
|
\_\_max: 1\n
|
142
139
|
\_\_bits: 26\n
|
143
|
-
\_\_key: 26\n
|
144
140
|
\_\_bucket_size : 1\n
|
145
|
-
\_\_sphere_version : 1\n
|
146
|
-
\_\_text_version : 1\n
|
147
|
-
\_\_version : 1\n
|
148
141
|
\_\_weights: { content: 1, title: 2 }\n
|
149
142
|
\_\_expire_after_seconds: number_of_seconds\n
|
150
|
-
\_\_partial_filter_expression\n
|
151
|
-
\_\_storage_engine\n
|
152
|
-
\_\_language_override\n
|
153
|
-
\_\_default_language\n
|
154
|
-
\_\_collation\n
|
155
143
|
Valid types are: 1, -1, '2d', '2dsphere', 'geoHaystack', 'text', 'hashed'\n\n
|
156
144
|
Example:\n
|
157
145
|
\_\_class Band\n
|
@@ -177,6 +165,25 @@ en:
|
|
177
165
|
collection. Double check the relation definitions and fix any
|
178
166
|
instances where embedded documents are improperly referenced
|
179
167
|
from other collections."
|
168
|
+
invalid_persistence_option:
|
169
|
+
message: "Invalid persistence option :%{invalid}."
|
170
|
+
summary: "The options used to change the persistence context must be one
|
171
|
+
of the valid options for a mongo client, or a collection name."
|
172
|
+
resolution: "Valid options are: %{valid}, make sure these are the ones
|
173
|
+
you are using."
|
174
|
+
invalid_relation:
|
175
|
+
message: "Defining a relation named '%{name}' is not allowed."
|
176
|
+
summary: "Defining this relation would override the method '%{name}',
|
177
|
+
which would cause issues with expectations around the original
|
178
|
+
method and cause extremely hard to debug issues. The original
|
179
|
+
method was defined in:\n
|
180
|
+
\_\_Object: %{origin}\n
|
181
|
+
\_\_File: %{file}\n
|
182
|
+
\_\_Line: %{line}"
|
183
|
+
resolution: "Use Mongoid.destructive_fields to see what names are not
|
184
|
+
allowed, and don't use these names. These include names that also
|
185
|
+
conflict with core Ruby methods on Object, Module, Enumerable, or
|
186
|
+
included gems that inject methods into these or Mongoid internals."
|
180
187
|
invalid_scope:
|
181
188
|
message: "Defining a scope of value %{value} on %{klass} is not
|
182
189
|
allowed."
|
data/lib/mongoid.rb
CHANGED
@@ -12,11 +12,11 @@ require "active_support/inflector"
|
|
12
12
|
require "active_support/time_with_zone"
|
13
13
|
require "active_model"
|
14
14
|
|
15
|
-
require "origin"
|
16
15
|
require "mongo"
|
17
16
|
|
18
17
|
require "mongoid/version"
|
19
18
|
require "mongoid/config"
|
19
|
+
require "mongoid/persistence_context"
|
20
20
|
require "mongoid/loggable"
|
21
21
|
require "mongoid/clients"
|
22
22
|
require "mongoid/document"
|
@@ -36,11 +36,6 @@ module Mongoid
|
|
36
36
|
extend Loggable
|
37
37
|
extend self
|
38
38
|
|
39
|
-
# A string added to the platform details of Ruby driver client handshake documents.
|
40
|
-
#
|
41
|
-
# @since 6.1.0
|
42
|
-
PLATFORM_DETAILS = "mongoid-#{VERSION}".freeze
|
43
|
-
|
44
39
|
# The minimum MongoDB version supported.
|
45
40
|
MONGODB_VERSION = "2.4.0"
|
46
41
|
|
@@ -65,7 +60,7 @@ module Mongoid
|
|
65
60
|
#
|
66
61
|
# @return [ Mongo::Client ] The default client.
|
67
62
|
#
|
68
|
-
# @since
|
63
|
+
# @since 5.0.0
|
69
64
|
def default_client
|
70
65
|
Clients.default
|
71
66
|
end
|
@@ -77,7 +72,7 @@ module Mongoid
|
|
77
72
|
#
|
78
73
|
# @return [ true ] True.
|
79
74
|
#
|
80
|
-
# @since
|
75
|
+
# @since 5.0.0
|
81
76
|
def disconnect_clients
|
82
77
|
Clients.disconnect
|
83
78
|
end
|
@@ -89,7 +84,7 @@ module Mongoid
|
|
89
84
|
#
|
90
85
|
# @return [ Mongo::Client ] The named client.
|
91
86
|
#
|
92
|
-
# @since
|
87
|
+
# @since 5.0.0
|
93
88
|
def client(name)
|
94
89
|
Clients.with_name(name)
|
95
90
|
end
|
data/lib/mongoid/atomic.rb
CHANGED
@@ -31,7 +31,7 @@ module Mongoid
|
|
31
31
|
# @example Add the atomic pull.
|
32
32
|
# person.add_atomic_pull(address)
|
33
33
|
#
|
34
|
-
# @param [ Document ]
|
34
|
+
# @param [ Document ] The embedded document to pull.
|
35
35
|
#
|
36
36
|
# @since 2.2.0
|
37
37
|
def add_atomic_pull(document)
|
@@ -68,7 +68,7 @@ module Mongoid
|
|
68
68
|
modifications.each_pair do |field, value|
|
69
69
|
push_fields[field] = field
|
70
70
|
mods = push_conflict?(field) ? conflicting_pushes : pushes
|
71
|
-
add_operation(mods, field,
|
71
|
+
add_operation(mods, field, Array.wrap(value))
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -118,12 +118,8 @@ module Mongoid
|
|
118
118
|
# @since 2.2.0
|
119
119
|
def add_operation(mods, field, value)
|
120
120
|
if mods.has_key?(field)
|
121
|
-
|
122
|
-
|
123
|
-
mods[field].push(val)
|
124
|
-
end
|
125
|
-
elsif mods[field]['$each']
|
126
|
-
mods[field]['$each'].concat(value['$each'])
|
121
|
+
value.each do |val|
|
122
|
+
mods[field].push(val)
|
127
123
|
end
|
128
124
|
else
|
129
125
|
mods[field] = value
|
@@ -194,7 +190,7 @@ module Mongoid
|
|
194
190
|
#
|
195
191
|
# @since 2.2.0
|
196
192
|
def conflicting_pushes
|
197
|
-
conflicts["$
|
193
|
+
conflicts["$pushAll"] ||= {}
|
198
194
|
end
|
199
195
|
|
200
196
|
# Get the conflicting set modifications.
|
@@ -281,16 +277,16 @@ module Mongoid
|
|
281
277
|
self["$pull"] ||= {}
|
282
278
|
end
|
283
279
|
|
284
|
-
# Get the $
|
280
|
+
# Get the $pushAll operations or intialize a new one.
|
285
281
|
#
|
286
|
-
# @example Get the $
|
282
|
+
# @example Get the $pushAll operations.
|
287
283
|
# modifiers.pushes
|
288
284
|
#
|
289
|
-
# @return [ Hash ] The $
|
285
|
+
# @return [ Hash ] The $pushAll operations.
|
290
286
|
#
|
291
287
|
# @since 2.1.0
|
292
288
|
def pushes
|
293
|
-
self["$
|
289
|
+
self["$pushAll"] ||= {}
|
294
290
|
end
|
295
291
|
|
296
292
|
# Get the $set operations or intialize a new one.
|
data/lib/mongoid/attributes.rb
CHANGED
@@ -139,14 +139,12 @@ module Mongoid
|
|
139
139
|
#
|
140
140
|
# @since 1.0.0
|
141
141
|
def remove_attribute(name)
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
delayed_atomic_unsets[atomic_attribute_name(access)] = [] unless new_record?
|
149
|
-
attributes.delete(access)
|
142
|
+
as_writable_attribute!(name) do |access|
|
143
|
+
_assigning do
|
144
|
+
attribute_will_change!(access)
|
145
|
+
delayed_atomic_unsets[atomic_attribute_name(access)] = [] unless new_record?
|
146
|
+
attributes.delete(access)
|
147
|
+
end
|
150
148
|
end
|
151
149
|
end
|
152
150
|
|
@@ -165,8 +163,7 @@ module Mongoid
|
|
165
163
|
#
|
166
164
|
# @since 1.0.0
|
167
165
|
def write_attribute(name, value)
|
168
|
-
|
169
|
-
if attribute_writable?(access)
|
166
|
+
as_writable_attribute!(name) do |access|
|
170
167
|
_assigning do
|
171
168
|
validate_attribute_value(access, value)
|
172
169
|
localized = fields[access].try(:localized?)
|
@@ -218,6 +215,7 @@ module Mongoid
|
|
218
215
|
# person.attributes = { :title => "Mr." }
|
219
216
|
#
|
220
217
|
# @param [ Hash ] attrs The new attributes to set.
|
218
|
+
# @param [ Boolean ] guard_protected_attributes False to skip mass assignment protection.
|
221
219
|
#
|
222
220
|
# @since 1.0.0
|
223
221
|
def write_attributes(attrs = nil)
|
@@ -331,7 +329,7 @@ module Mongoid
|
|
331
329
|
# the value is valid for given a field.
|
332
330
|
# For now, only Hash and Array fields are validated.
|
333
331
|
#
|
334
|
-
# @param [ String, Symbol ]
|
332
|
+
# @param [ String, Symbol ] name The name of the attribute to validate.
|
335
333
|
# @param [ Object ] value The to be validated.
|
336
334
|
#
|
337
335
|
# @since 3.0.10
|
@@ -13,8 +13,7 @@ module Mongoid
|
|
13
13
|
# @example Does this object respond to the method?
|
14
14
|
# person.respond_to?(:title)
|
15
15
|
#
|
16
|
-
# @param [ Array ]
|
17
|
-
# @param [ true, false ] include_private
|
16
|
+
# @param [ Array ] *args The name of the method.
|
18
17
|
#
|
19
18
|
# @return [ true, false ] True if it does, false if not.
|
20
19
|
#
|
@@ -38,7 +37,7 @@ module Mongoid
|
|
38
37
|
# @since 4.0.0
|
39
38
|
def define_dynamic_reader(name)
|
40
39
|
return unless name.valid_method_name?
|
41
|
-
class_eval <<-READER
|
40
|
+
class_eval <<-READER
|
42
41
|
def #{name}
|
43
42
|
attribute_will_change!(#{name.inspect})
|
44
43
|
read_attribute(#{name.inspect})
|
@@ -57,7 +56,7 @@ module Mongoid
|
|
57
56
|
#
|
58
57
|
# @since 4.0.0
|
59
58
|
def define_dynamic_before_type_cast_reader(name)
|
60
|
-
class_eval <<-READER
|
59
|
+
class_eval <<-READER
|
61
60
|
def #{name}_before_type_cast
|
62
61
|
attribute_will_change!(#{name.inspect})
|
63
62
|
read_attribute_before_type_cast(#{name.inspect})
|
@@ -78,7 +77,7 @@ module Mongoid
|
|
78
77
|
def define_dynamic_writer(name)
|
79
78
|
return unless name.valid_method_name?
|
80
79
|
|
81
|
-
class_eval <<-WRITER
|
80
|
+
class_eval <<-WRITER
|
82
81
|
def #{name}=(value)
|
83
82
|
write_attribute(#{name.inspect}, value)
|
84
83
|
end
|
@@ -127,7 +126,7 @@ module Mongoid
|
|
127
126
|
# document.method_missing(:test)
|
128
127
|
#
|
129
128
|
# @param [ String, Symbol ] name The name of the method.
|
130
|
-
# @param [ Array ] args The arguments to the method.
|
129
|
+
# @param [ Array ] *args The arguments to the method.
|
131
130
|
#
|
132
131
|
# @return [ Object ] The result of the method call.
|
133
132
|
#
|
@@ -34,7 +34,7 @@ module Mongoid
|
|
34
34
|
# accepts_nested_attributes_for :addresses, :game, :posts
|
35
35
|
# end
|
36
36
|
#
|
37
|
-
# @param [ Array<Symbol>, Hash ] args A list of relation names, followed
|
37
|
+
# @param [ Array<Symbol>, Hash ] *args A list of relation names, followed
|
38
38
|
# by a hash of options.
|
39
39
|
#
|
40
40
|
# @option *args [ true, false ] :allow_destroy Can deletion occur?
|
@@ -118,6 +118,8 @@ module Mongoid
|
|
118
118
|
# @example Process the pending items.
|
119
119
|
# document.process_pending
|
120
120
|
#
|
121
|
+
# @param [ Hash ] options The mass assignment options.
|
122
|
+
#
|
121
123
|
# @since 2.0.0.rc.7
|
122
124
|
def process_pending
|
123
125
|
process_nested and process_relations
|
@@ -130,6 +132,8 @@ module Mongoid
|
|
130
132
|
# @example Process the relations.
|
131
133
|
# document.process_relations
|
132
134
|
#
|
135
|
+
# @param [ Hash ] options The mass assignment options.
|
136
|
+
#
|
133
137
|
# @since 2.0.0.rc.7
|
134
138
|
def process_relations
|
135
139
|
pending_relations.each_pair do |name, value|
|
@@ -22,10 +22,32 @@ module Mongoid
|
|
22
22
|
# readonly.
|
23
23
|
#
|
24
24
|
# @since 3.0.0
|
25
|
+
#
|
26
|
+
# @deprecated Use #as_writable_attribute! instead.
|
25
27
|
def attribute_writable?(name)
|
26
28
|
new_record? || !readonly_attributes.include?(database_field_name(name))
|
27
29
|
end
|
28
30
|
|
31
|
+
private
|
32
|
+
|
33
|
+
def as_writable_attribute!(name, value = :nil)
|
34
|
+
normalized_name = database_field_name(name)
|
35
|
+
if new_record? || (!readonly_attributes.include?(normalized_name) && loaded?(normalized_name))
|
36
|
+
yield(normalized_name)
|
37
|
+
else
|
38
|
+
raise Errors::ReadonlyAttribute.new(name, value)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def loaded?(name)
|
43
|
+
__selected_fields.nil? || projected_field?(name)
|
44
|
+
end
|
45
|
+
|
46
|
+
def projected_field?(name)
|
47
|
+
projected = (__selected_fields || {}).keys.select { |f| __selected_fields[f] == 1 }
|
48
|
+
projected.empty? || projected.include?(name)
|
49
|
+
end
|
50
|
+
|
29
51
|
module ClassMethods
|
30
52
|
|
31
53
|
# Defines an attribute as readonly. This will ensure that the value for
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Mongoid
|
3
|
+
|
4
|
+
# Encapsulates behaviour around caching.
|
5
|
+
#
|
6
|
+
# @since 6.0.0
|
7
|
+
module Cacheable
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
cattr_accessor :cache_timestamp_format, instance_writer: false
|
12
|
+
self.cache_timestamp_format = :nsec
|
13
|
+
end
|
14
|
+
|
15
|
+
# Print out the cache key. This will append different values on the
|
16
|
+
# plural model name.
|
17
|
+
#
|
18
|
+
# If new_record? - will append /new
|
19
|
+
# If not - will append /id-updated_at.to_s(cache_timestamp_format)
|
20
|
+
# Without updated_at - will append /id
|
21
|
+
#
|
22
|
+
# This is usually called insode a cache() block
|
23
|
+
#
|
24
|
+
# @example Returns the cache key
|
25
|
+
# document.cache_key
|
26
|
+
#
|
27
|
+
# @return [ String ] the string with or without updated_at
|
28
|
+
#
|
29
|
+
# @since 2.4.0
|
30
|
+
def cache_key
|
31
|
+
return "#{model_key}/new" if new_record?
|
32
|
+
return "#{model_key}/#{id}-#{updated_at.utc.to_s(cache_timestamp_format)}" if do_or_do_not(:updated_at)
|
33
|
+
"#{model_key}/#{id}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/mongoid/changeable.rb
CHANGED
@@ -265,7 +265,7 @@ module Mongoid
|
|
265
265
|
# Model.create_dirty_methods("name", "name")
|
266
266
|
#
|
267
267
|
# @param [ String ] name The name of the field.
|
268
|
-
# @param [ String ]
|
268
|
+
# @param [ String ] name The name of the accessor.
|
269
269
|
#
|
270
270
|
# @return [ Module ] The fields module.
|
271
271
|
#
|
@@ -278,6 +278,8 @@ module Mongoid
|
|
278
278
|
create_dirty_previous_value_accessor(name, meth)
|
279
279
|
create_dirty_reset(name, meth)
|
280
280
|
create_dirty_reset_to_default(name, meth)
|
281
|
+
create_dirty_previously_changed?(name, meth)
|
282
|
+
create_dirty_previous_change(name, meth)
|
281
283
|
end
|
282
284
|
|
283
285
|
# Creates the dirty change accessor.
|
@@ -398,6 +400,40 @@ module Mongoid
|
|
398
400
|
end
|
399
401
|
end
|
400
402
|
end
|
403
|
+
|
404
|
+
# Creates the dirty change check.
|
405
|
+
#
|
406
|
+
# @example Create the dirty change check.
|
407
|
+
# Model.create_dirty_previously_changed?("name", "alias")
|
408
|
+
#
|
409
|
+
# @param [ String ] name The attribute name.
|
410
|
+
# @param [ String ] meth The name of the accessor.
|
411
|
+
#
|
412
|
+
# @since 6.0.0
|
413
|
+
def create_dirty_previously_changed?(name, meth)
|
414
|
+
generated_methods.module_eval do
|
415
|
+
re_define_method("#{meth}_previously_changed?") do
|
416
|
+
previous_changes.keys.include?(name)
|
417
|
+
end
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
# Creates the dirty change accessor.
|
422
|
+
#
|
423
|
+
# @example Create the dirty change accessor.
|
424
|
+
# Model.create_dirty_previous_change("name", "alias")
|
425
|
+
#
|
426
|
+
# @param [ String ] name The attribute name.
|
427
|
+
# @param [ String ] meth The name of the accessor.
|
428
|
+
#
|
429
|
+
# @since 6.0.0
|
430
|
+
def create_dirty_previous_change(name, meth)
|
431
|
+
generated_methods.module_eval do
|
432
|
+
re_define_method("#{meth}_previous_change") do
|
433
|
+
previous_changes[name]
|
434
|
+
end
|
435
|
+
end
|
436
|
+
end
|
401
437
|
end
|
402
438
|
end
|
403
439
|
end
|