mongoid 7.4.3 → 8.0.7
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 +3 -3
- data/Rakefile +25 -0
- data/lib/config/locales/en.yml +52 -28
- data/lib/mongoid/association/accessors.rb +38 -9
- data/lib/mongoid/association/bindable.rb +50 -2
- data/lib/mongoid/association/builders.rb +4 -2
- data/lib/mongoid/association/constrainable.rb +0 -1
- data/lib/mongoid/association/eager_loadable.rb +29 -7
- data/lib/mongoid/association/embedded/batchable.rb +33 -10
- data/lib/mongoid/association/embedded/cyclic.rb +1 -1
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +24 -2
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +2 -2
- data/lib/mongoid/association/embedded/embedded_in.rb +3 -2
- data/lib/mongoid/association/embedded/embeds_many/binding.rb +1 -0
- data/lib/mongoid/association/embedded/embeds_many/buildable.rb +1 -1
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +65 -41
- data/lib/mongoid/association/embedded/embeds_many.rb +2 -2
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +18 -4
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +23 -4
- data/lib/mongoid/association/embedded/embeds_one.rb +3 -3
- data/lib/mongoid/association/macros.rb +28 -1
- data/lib/mongoid/association/many.rb +11 -7
- data/lib/mongoid/association/nested/many.rb +5 -4
- data/lib/mongoid/association/nested/nested_buildable.rb +4 -4
- data/lib/mongoid/association/nested/one.rb +5 -5
- data/lib/mongoid/association/one.rb +2 -2
- data/lib/mongoid/association/options.rb +9 -9
- data/lib/mongoid/association/proxy.rb +14 -3
- data/lib/mongoid/association/referenced/auto_save.rb +4 -3
- data/lib/mongoid/association/referenced/belongs_to/binding.rb +1 -0
- data/lib/mongoid/association/referenced/belongs_to/buildable.rb +1 -1
- data/lib/mongoid/association/referenced/belongs_to/proxy.rb +5 -6
- data/lib/mongoid/association/referenced/belongs_to.rb +2 -2
- data/lib/mongoid/association/referenced/counter_cache.rb +10 -10
- data/lib/mongoid/association/referenced/eager.rb +2 -2
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +70 -13
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +6 -3
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +20 -24
- data/lib/mongoid/association/referenced/has_many/proxy.rb +26 -16
- data/lib/mongoid/association/referenced/has_many.rb +3 -3
- data/lib/mongoid/association/referenced/has_one/buildable.rb +1 -1
- data/lib/mongoid/association/referenced/has_one/nested_builder.rb +5 -5
- data/lib/mongoid/association/referenced/has_one/proxy.rb +9 -12
- data/lib/mongoid/association/referenced/has_one.rb +3 -3
- data/lib/mongoid/association/referenced/syncable.rb +4 -4
- data/lib/mongoid/association/reflections.rb +2 -2
- data/lib/mongoid/association/relatable.rb +44 -10
- data/lib/mongoid/association.rb +5 -5
- data/lib/mongoid/atomic/modifiers.rb +2 -2
- data/lib/mongoid/atomic.rb +7 -0
- data/lib/mongoid/attributes/dynamic.rb +3 -3
- data/lib/mongoid/attributes/nested.rb +5 -5
- data/lib/mongoid/attributes/processing.rb +37 -6
- data/lib/mongoid/attributes/projector.rb +1 -1
- data/lib/mongoid/attributes/readonly.rb +2 -2
- data/lib/mongoid/attributes.rb +43 -40
- data/lib/mongoid/cacheable.rb +2 -2
- data/lib/mongoid/changeable.rb +43 -10
- data/lib/mongoid/clients/options.rb +5 -1
- data/lib/mongoid/clients/sessions.rb +2 -14
- data/lib/mongoid/clients/validators/storage.rb +3 -3
- data/lib/mongoid/config/options.rb +3 -0
- data/lib/mongoid/config/validators/client.rb +6 -6
- data/lib/mongoid/config.rb +62 -17
- data/lib/mongoid/contextual/aggregable/memory.rb +24 -16
- data/lib/mongoid/contextual/aggregable/mongo.rb +5 -5
- data/lib/mongoid/contextual/aggregable/none.rb +1 -1
- data/lib/mongoid/contextual/atomic.rb +1 -1
- data/lib/mongoid/contextual/geo_near.rb +7 -7
- data/lib/mongoid/contextual/map_reduce.rb +2 -2
- data/lib/mongoid/contextual/memory.rb +180 -21
- data/lib/mongoid/contextual/mongo.rb +260 -217
- data/lib/mongoid/contextual/none.rb +67 -5
- data/lib/mongoid/contextual/queryable.rb +1 -1
- data/lib/mongoid/contextual.rb +2 -2
- data/lib/mongoid/copyable.rb +32 -8
- data/lib/mongoid/criteria/findable.rb +7 -4
- data/lib/mongoid/criteria/includable.rb +24 -20
- data/lib/mongoid/criteria/marshalable.rb +10 -2
- data/lib/mongoid/criteria/permission.rb +1 -1
- data/lib/mongoid/criteria/queryable/aggregable.rb +2 -2
- data/lib/mongoid/criteria/queryable/extensions/array.rb +3 -14
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +25 -4
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +2 -2
- data/lib/mongoid/criteria/queryable/extensions/date.rb +6 -1
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +6 -1
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +1 -15
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -9
- data/lib/mongoid/criteria/queryable/extensions/object.rb +2 -1
- data/lib/mongoid/criteria/queryable/extensions/range.rb +13 -5
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +3 -3
- data/lib/mongoid/criteria/queryable/extensions/set.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/string.rb +4 -14
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +4 -12
- data/lib/mongoid/criteria/queryable/extensions/time.rb +6 -1
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +6 -1
- data/lib/mongoid/criteria/queryable/key.rb +3 -3
- data/lib/mongoid/criteria/queryable/mergeable.rb +21 -0
- data/lib/mongoid/criteria/queryable/optional.rb +5 -11
- data/lib/mongoid/criteria/queryable/options.rb +2 -2
- data/lib/mongoid/criteria/queryable/pipeline.rb +1 -1
- data/lib/mongoid/criteria/queryable/selectable.rb +31 -37
- data/lib/mongoid/criteria/queryable/selector.rb +93 -8
- data/lib/mongoid/criteria/queryable/smash.rb +40 -7
- data/lib/mongoid/criteria/queryable/storable.rb +1 -1
- data/lib/mongoid/criteria/queryable.rb +12 -7
- data/lib/mongoid/criteria/scopable.rb +2 -2
- data/lib/mongoid/criteria/translator.rb +45 -0
- data/lib/mongoid/criteria.rb +16 -35
- data/lib/mongoid/deprecable.rb +37 -0
- data/lib/mongoid/deprecation.rb +25 -0
- data/lib/mongoid/document.rb +135 -34
- data/lib/mongoid/equality.rb +8 -8
- data/lib/mongoid/errors/document_not_found.rb +33 -12
- data/lib/mongoid/errors/invalid_config_option.rb +1 -1
- data/lib/mongoid/errors/invalid_dependent_strategy.rb +1 -1
- data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +23 -0
- data/lib/mongoid/errors/invalid_field.rb +6 -2
- data/lib/mongoid/errors/invalid_field_type.rb +26 -0
- data/lib/mongoid/errors/invalid_relation.rb +1 -1
- data/lib/mongoid/errors/invalid_relation_option.rb +1 -1
- data/lib/mongoid/errors/invalid_session_use.rb +1 -1
- data/lib/mongoid/errors/invalid_storage_options.rb +1 -1
- data/lib/mongoid/errors/mongoid_error.rb +3 -3
- data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +1 -1
- data/lib/mongoid/errors/no_client_database.rb +1 -1
- data/lib/mongoid/errors/no_client_hosts.rb +1 -1
- data/lib/mongoid/errors/readonly_attribute.rb +1 -1
- data/lib/mongoid/errors/too_many_nested_attribute_records.rb +1 -1
- data/lib/mongoid/errors/unknown_attribute.rb +1 -1
- data/lib/mongoid/errors.rb +2 -2
- data/lib/mongoid/extensions/array.rb +9 -7
- data/lib/mongoid/extensions/big_decimal.rb +33 -10
- data/lib/mongoid/extensions/binary.rb +42 -0
- data/lib/mongoid/extensions/boolean.rb +8 -2
- data/lib/mongoid/extensions/date.rb +26 -20
- data/lib/mongoid/extensions/date_time.rb +1 -1
- data/lib/mongoid/extensions/false_class.rb +1 -1
- data/lib/mongoid/extensions/float.rb +7 -4
- data/lib/mongoid/extensions/hash.rb +37 -8
- data/lib/mongoid/extensions/integer.rb +7 -4
- data/lib/mongoid/extensions/module.rb +1 -1
- data/lib/mongoid/extensions/object.rb +8 -6
- data/lib/mongoid/extensions/range.rb +41 -10
- data/lib/mongoid/extensions/regexp.rb +11 -4
- data/lib/mongoid/extensions/set.rb +11 -4
- data/lib/mongoid/extensions/string.rb +11 -22
- data/lib/mongoid/extensions/symbol.rb +4 -15
- data/lib/mongoid/extensions/time.rb +27 -16
- data/lib/mongoid/extensions/time_with_zone.rb +1 -2
- data/lib/mongoid/extensions/true_class.rb +1 -1
- data/lib/mongoid/extensions.rb +1 -0
- data/lib/mongoid/factory.rb +55 -7
- data/lib/mongoid/fields/foreign_key.rb +11 -4
- data/lib/mongoid/fields/localized.rb +9 -4
- data/lib/mongoid/fields/standard.rb +7 -7
- data/lib/mongoid/fields/validators/macro.rb +3 -9
- data/lib/mongoid/fields.rb +233 -40
- data/lib/mongoid/findable.rb +34 -13
- data/lib/mongoid/indexable/specification.rb +2 -2
- data/lib/mongoid/indexable/validators/options.rb +6 -2
- data/lib/mongoid/interceptable.rb +185 -16
- data/lib/mongoid/matchable.rb +1 -1
- data/lib/mongoid/matcher.rb +33 -13
- data/lib/mongoid/persistable/creatable.rb +18 -9
- data/lib/mongoid/persistable/deletable.rb +1 -1
- data/lib/mongoid/persistable/destroyable.rb +1 -1
- data/lib/mongoid/persistable/savable.rb +2 -2
- data/lib/mongoid/persistable/unsettable.rb +1 -1
- data/lib/mongoid/persistable/updatable.rb +19 -12
- data/lib/mongoid/persistable/upsertable.rb +1 -1
- data/lib/mongoid/persistable.rb +3 -3
- data/lib/mongoid/persistence_context.rb +63 -10
- data/lib/mongoid/query_cache.rb +8 -260
- data/lib/mongoid/railties/controller_runtime.rb +1 -1
- data/lib/mongoid/reloadable.rb +10 -8
- data/lib/mongoid/scopable.rb +26 -22
- data/lib/mongoid/selectable.rb +1 -2
- data/lib/mongoid/serializable.rb +10 -6
- data/lib/mongoid/shardable.rb +35 -11
- data/lib/mongoid/stateful.rb +35 -9
- data/lib/mongoid/tasks/database.rb +0 -2
- data/lib/mongoid/threaded/lifecycle.rb +5 -5
- data/lib/mongoid/threaded.rb +42 -12
- data/lib/mongoid/timestamps/created.rb +1 -1
- data/lib/mongoid/timestamps/updated.rb +2 -2
- data/lib/mongoid/touchable.rb +2 -3
- data/lib/mongoid/traversable.rb +5 -4
- data/lib/mongoid/validatable/localizable.rb +1 -1
- data/lib/mongoid/validatable/macros.rb +0 -2
- data/lib/mongoid/validatable/presence.rb +2 -2
- data/lib/mongoid/validatable/uniqueness.rb +9 -8
- data/lib/mongoid/validatable.rb +6 -6
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid/warnings.rb +28 -0
- data/lib/mongoid.rb +2 -0
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +4 -3
- data/spec/config/mongoid.yml +16 -0
- data/spec/integration/app_spec.rb +8 -12
- data/spec/integration/associations/belongs_to_spec.rb +18 -0
- data/spec/integration/associations/embedded_spec.rb +15 -0
- data/spec/integration/associations/embeds_many_spec.rb +15 -2
- data/spec/integration/associations/embeds_one_spec.rb +18 -0
- data/spec/integration/associations/foreign_key_spec.rb +9 -0
- data/spec/integration/associations/has_and_belongs_to_many_spec.rb +21 -0
- data/spec/integration/associations/has_one_spec.rb +97 -1
- data/spec/integration/associations/scope_option_spec.rb +1 -1
- data/spec/integration/callbacks_models.rb +95 -1
- data/spec/integration/callbacks_spec.rb +246 -4
- data/spec/integration/criteria/range_spec.rb +95 -1
- data/spec/integration/discriminator_key_spec.rb +115 -76
- data/spec/integration/dots_and_dollars_spec.rb +277 -0
- data/spec/integration/i18n_fallbacks_spec.rb +1 -17
- data/spec/integration/matcher_examples_spec.rb +20 -13
- data/spec/integration/matcher_operator_data/type_decimal.yml +3 -2
- data/spec/integration/matcher_operator_spec.rb +3 -5
- data/spec/integration/persistence/range_field_spec.rb +350 -0
- data/spec/mongoid/association/counter_cache_spec.rb +1 -1
- data/spec/mongoid/association/depending_spec.rb +9 -9
- data/spec/mongoid/association/eager_spec.rb +2 -1
- data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +2 -1
- data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +54 -0
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +69 -9
- data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +112 -0
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +235 -40
- data/spec/mongoid/association/embedded/embeds_many_models.rb +36 -0
- data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +12 -0
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +68 -0
- data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +25 -0
- data/spec/mongoid/association/embedded/embeds_one_models.rb +19 -0
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +28 -0
- data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +2 -1
- data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +54 -0
- data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +15 -0
- data/spec/mongoid/association/referenced/belongs_to_models.rb +11 -0
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +2 -2
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +202 -201
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +25 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +35 -2
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +109 -0
- data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +8 -8
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +160 -119
- data/spec/mongoid/association/referenced/has_many_models.rb +3 -1
- data/spec/mongoid/association/referenced/has_many_spec.rb +25 -0
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +2 -2
- data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +107 -1
- data/spec/mongoid/association/referenced/has_one_models.rb +16 -0
- data/spec/mongoid/association/syncable_spec.rb +14 -0
- data/spec/mongoid/atomic/paths_spec.rb +0 -14
- data/spec/mongoid/attributes/nested_spec.rb +80 -11
- data/spec/mongoid/attributes/nested_spec_models.rb +48 -0
- data/spec/mongoid/attributes/projector_spec.rb +1 -5
- data/spec/mongoid/attributes_spec.rb +551 -27
- data/spec/mongoid/cacheable_spec.rb +3 -3
- data/spec/mongoid/changeable_spec.rb +130 -13
- data/spec/mongoid/clients/factory_spec.rb +23 -30
- data/spec/mongoid/clients/options_spec.rb +1 -0
- data/spec/mongoid/clients/sessions_spec.rb +0 -38
- data/spec/mongoid/clients_spec.rb +57 -2
- data/spec/mongoid/config_spec.rb +78 -18
- data/spec/mongoid/contextual/aggregable/memory_spec.rb +396 -158
- data/spec/mongoid/contextual/aggregable/memory_table.yml +88 -0
- data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +62 -0
- data/spec/mongoid/contextual/map_reduce_spec.rb +2 -16
- data/spec/mongoid/contextual/memory_spec.rb +1336 -69
- data/spec/mongoid/contextual/mongo_spec.rb +1253 -247
- data/spec/mongoid/contextual/none_spec.rb +38 -0
- data/spec/mongoid/copyable_spec.rb +451 -1
- data/spec/mongoid/criteria/findable_spec.rb +86 -210
- data/spec/mongoid/criteria/includable_spec.rb +1492 -0
- data/spec/mongoid/criteria/includable_spec_models.rb +54 -0
- data/spec/mongoid/criteria/marshalable_spec.rb +18 -1
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +7 -19
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +134 -26
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +11 -0
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +11 -0
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +0 -15
- data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +73 -7
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +0 -59
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +0 -59
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +11 -0
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +11 -0
- data/spec/mongoid/criteria/queryable/optional_spec.rb +15 -484
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +50 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +289 -124
- data/spec/mongoid/criteria/queryable/selector_spec.rb +89 -4
- data/spec/mongoid/criteria/queryable/storable_spec.rb +72 -0
- data/spec/mongoid/criteria/translator_spec.rb +132 -0
- data/spec/mongoid/criteria_projection_spec.rb +0 -1
- data/spec/mongoid/criteria_spec.rb +475 -1199
- data/spec/mongoid/document_fields_spec.rb +173 -24
- data/spec/mongoid/document_spec.rb +32 -41
- data/spec/mongoid/errors/document_not_found_spec.rb +76 -0
- data/spec/mongoid/errors/invalid_field_spec.rb +1 -1
- data/spec/mongoid/errors/invalid_field_type_spec.rb +55 -0
- data/spec/mongoid/errors/mongoid_error_spec.rb +3 -1
- data/spec/mongoid/errors/no_environment_spec.rb +3 -3
- data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +1 -1
- data/spec/mongoid/extensions/array_spec.rb +16 -2
- data/spec/mongoid/extensions/big_decimal_spec.rb +712 -212
- data/spec/mongoid/extensions/binary_spec.rb +44 -9
- data/spec/mongoid/extensions/boolean_spec.rb +68 -82
- data/spec/mongoid/extensions/date_class_mongoize_spec.rb +7 -3
- data/spec/mongoid/extensions/date_spec.rb +71 -1
- data/spec/mongoid/extensions/date_time_spec.rb +15 -9
- data/spec/mongoid/extensions/float_spec.rb +53 -74
- data/spec/mongoid/extensions/hash_spec.rb +33 -3
- data/spec/mongoid/extensions/integer_spec.rb +50 -64
- data/spec/mongoid/extensions/range_spec.rb +255 -54
- data/spec/mongoid/extensions/regexp_spec.rb +58 -33
- data/spec/mongoid/extensions/set_spec.rb +106 -0
- data/spec/mongoid/extensions/string_spec.rb +53 -25
- data/spec/mongoid/extensions/symbol_spec.rb +18 -25
- data/spec/mongoid/extensions/time_spec.rb +634 -66
- data/spec/mongoid/extensions/time_with_zone_spec.rb +17 -31
- data/spec/mongoid/factory_spec.rb +61 -1
- data/spec/mongoid/fields/localized_spec.rb +37 -12
- data/spec/mongoid/fields_spec.rb +364 -50
- data/spec/mongoid/findable_spec.rb +80 -15
- data/spec/mongoid/indexable/specification_spec.rb +2 -2
- data/spec/mongoid/indexable_spec.rb +39 -20
- data/spec/mongoid/interceptable_spec.rb +807 -27
- data/spec/mongoid/interceptable_spec_models.rb +235 -4
- data/spec/mongoid/matcher/extract_attribute_spec.rb +1 -5
- data/spec/mongoid/mongoizable_spec.rb +285 -0
- data/spec/mongoid/persistable/creatable_spec.rb +2 -2
- data/spec/mongoid/persistable/deletable_spec.rb +2 -2
- data/spec/mongoid/persistable/destroyable_spec.rb +2 -2
- data/spec/mongoid/persistable/upsertable_spec.rb +14 -0
- data/spec/mongoid/persistence_context_spec.rb +50 -1
- data/spec/mongoid/query_cache_middleware_spec.rb +0 -18
- data/spec/mongoid/query_cache_spec.rb +0 -154
- data/spec/mongoid/reloadable_spec.rb +59 -2
- data/spec/mongoid/scopable_spec.rb +54 -16
- data/spec/mongoid/shardable_models.rb +14 -0
- data/spec/mongoid/shardable_spec.rb +157 -51
- data/spec/mongoid/stateful_spec.rb +28 -0
- data/spec/mongoid/timestamps_spec.rb +390 -0
- data/spec/mongoid/timestamps_spec_models.rb +67 -0
- data/spec/mongoid/touchable_spec.rb +116 -0
- data/spec/mongoid/touchable_spec_models.rb +12 -8
- data/spec/mongoid/traversable_spec.rb +4 -11
- data/spec/mongoid/validatable/presence_spec.rb +1 -1
- data/spec/mongoid/validatable/uniqueness_spec.rb +59 -31
- data/spec/mongoid/warnings_spec.rb +35 -0
- data/spec/mongoid_spec.rb +1 -1
- data/spec/rails/controller_extension/controller_runtime_spec.rb +2 -2
- data/spec/rails/mongoid_spec.rb +4 -16
- data/spec/shared/lib/mrss/docker_runner.rb +7 -0
- data/spec/shared/lib/mrss/lite_constraints.rb +10 -2
- data/spec/shared/lib/mrss/server_version_registry.rb +16 -23
- data/spec/shared/lib/mrss/utils.rb +28 -6
- data/spec/shared/share/Dockerfile.erb +36 -40
- data/spec/shared/shlib/server.sh +32 -8
- data/spec/shared/shlib/set_env.sh +4 -4
- data/spec/support/constraints.rb +24 -0
- data/spec/support/macros.rb +46 -0
- data/spec/support/models/augmentation.rb +12 -0
- data/spec/support/models/band.rb +3 -0
- data/spec/support/models/catalog.rb +24 -0
- data/spec/support/models/circus.rb +3 -0
- data/spec/support/models/code.rb +2 -0
- data/spec/support/models/fanatic.rb +8 -0
- data/spec/support/models/implant.rb +9 -0
- data/spec/support/models/label.rb +2 -0
- data/spec/support/models/passport.rb +9 -0
- data/spec/support/models/person.rb +2 -0
- data/spec/support/models/player.rb +2 -0
- data/spec/support/models/powerup.rb +12 -0
- data/spec/support/models/purse.rb +9 -0
- data/spec/support/models/registry.rb +1 -0
- data/spec/support/models/school.rb +14 -0
- data/spec/support/models/shield.rb +18 -0
- data/spec/support/models/student.rb +14 -0
- data/spec/support/models/weapon.rb +12 -0
- data.tar.gz.sig +4 -1
- metadata +682 -635
- metadata.gz.sig +0 -0
- data/lib/mongoid/errors/eager_load.rb +0 -23
- data/lib/mongoid/errors/invalid_value.rb +0 -17
- data/spec/mongoid/errors/eager_load_spec.rb +0 -31
@@ -48,7 +48,7 @@ module Mongoid
|
|
48
48
|
# @example Is the field a foreign key?
|
49
49
|
# field.foreign_key?
|
50
50
|
#
|
51
|
-
# @return [ true
|
51
|
+
# @return [ true | false ] If the field is a foreign key.
|
52
52
|
def foreign_key?
|
53
53
|
false
|
54
54
|
end
|
@@ -82,7 +82,7 @@ module Mongoid
|
|
82
82
|
# @example Is the field lazy?
|
83
83
|
# field.lazy?
|
84
84
|
#
|
85
|
-
# @return [ true
|
85
|
+
# @return [ true | false ] If the field is lazy.
|
86
86
|
def lazy?
|
87
87
|
false
|
88
88
|
end
|
@@ -92,7 +92,7 @@ module Mongoid
|
|
92
92
|
# @example Is the field localized?
|
93
93
|
# field.localized?
|
94
94
|
#
|
95
|
-
# @return [ true
|
95
|
+
# @return [ true | false ] If the field is localized.
|
96
96
|
def localized?
|
97
97
|
false
|
98
98
|
end
|
@@ -112,7 +112,7 @@ module Mongoid
|
|
112
112
|
# @example Is the field a BSON::ObjectId?
|
113
113
|
# field.object_id_field?
|
114
114
|
#
|
115
|
-
# @return [ true
|
115
|
+
# @return [ true | false ] If the field is a BSON::ObjectId.
|
116
116
|
def object_id_field?
|
117
117
|
@object_id_field ||= (type == BSON::ObjectId)
|
118
118
|
end
|
@@ -122,7 +122,7 @@ module Mongoid
|
|
122
122
|
# @example Does the field pre-process the default?
|
123
123
|
# field.pre_processed?
|
124
124
|
#
|
125
|
-
# @return [ true
|
125
|
+
# @return [ true | false ] If the field's default is pre-processed.
|
126
126
|
def pre_processed?
|
127
127
|
@pre_processed ||=
|
128
128
|
(options[:pre_processed] || (default_val && !default_val.is_a?(::Proc)))
|
@@ -161,7 +161,7 @@ module Mongoid
|
|
161
161
|
#
|
162
162
|
# @note Ruby's instance_exec was just too slow.
|
163
163
|
#
|
164
|
-
# @param [ Class
|
164
|
+
# @param [ Class | Module ] object The class or module the field is
|
165
165
|
# defined on.
|
166
166
|
def define_default_method(object)
|
167
167
|
object.__send__(:define_method, default_name, default_val)
|
@@ -177,7 +177,7 @@ module Mongoid
|
|
177
177
|
#
|
178
178
|
# @param [ Hash ] fields The field limitations.
|
179
179
|
#
|
180
|
-
# @return [ true
|
180
|
+
# @return [ true | false ] If the field was included.
|
181
181
|
def included?(fields)
|
182
182
|
(fields.values.first == 1 && fields[name.to_s] == 1) ||
|
183
183
|
(fields.values.first == 0 && !fields.has_key?(name.to_s))
|
@@ -8,9 +8,6 @@ module Mongoid
|
|
8
8
|
module Macro
|
9
9
|
extend self
|
10
10
|
|
11
|
-
# The warning message to give when a field is of type Symbol.
|
12
|
-
FIELD_TYPE_IS_SYMBOL = 'The BSON symbol type is deprecated; use String instead'.freeze
|
13
|
-
|
14
11
|
OPTIONS = [
|
15
12
|
:as,
|
16
13
|
:default,
|
@@ -69,7 +66,7 @@ module Mongoid
|
|
69
66
|
def validate_field_name(klass, name)
|
70
67
|
[name, "#{name}?".to_sym, "#{name}=".to_sym].each do |n|
|
71
68
|
if Mongoid.destructive_fields.include?(n)
|
72
|
-
raise Errors::InvalidField.new(klass, n)
|
69
|
+
raise Errors::InvalidField.new(klass, name, n)
|
73
70
|
end
|
74
71
|
end
|
75
72
|
end
|
@@ -91,7 +88,7 @@ module Mongoid
|
|
91
88
|
def validate_name_uniqueness(klass, name, options)
|
92
89
|
if !options[:overwrite] && klass.fields.keys.include?(name.to_s)
|
93
90
|
if Mongoid.duplicate_fields_exception
|
94
|
-
raise Errors::InvalidField.new(klass, name)
|
91
|
+
raise Errors::InvalidField.new(klass, name, name)
|
95
92
|
else
|
96
93
|
Mongoid.logger.warn("Overwriting existing field #{name} in class #{klass.name}.") if Mongoid.logger
|
97
94
|
end
|
@@ -117,10 +114,7 @@ module Mongoid
|
|
117
114
|
end
|
118
115
|
|
119
116
|
if option == :type && options[option] == Symbol
|
120
|
-
|
121
|
-
Mongoid.logger.warn(FIELD_TYPE_IS_SYMBOL)
|
122
|
-
true
|
123
|
-
end
|
117
|
+
Mongoid::Warnings.warn_symbol_type_deprecated
|
124
118
|
end
|
125
119
|
end
|
126
120
|
end
|
data/lib/mongoid/fields.rb
CHANGED
@@ -42,6 +42,11 @@ module Mongoid
|
|
42
42
|
# @api private
|
43
43
|
IDS = [ :_id, '_id', ].freeze
|
44
44
|
|
45
|
+
# BSON classes that are not supported as field types
|
46
|
+
#
|
47
|
+
# @api private
|
48
|
+
INVALID_BSON_CLASSES = [ BSON::Decimal128, BSON::Int32, BSON::Int64 ].freeze
|
49
|
+
|
45
50
|
module ClassMethods
|
46
51
|
# Returns the list of id fields for this model class, as both strings
|
47
52
|
# and symbols.
|
@@ -142,7 +147,7 @@ module Mongoid
|
|
142
147
|
# @example Apply all the non-proc defaults.
|
143
148
|
# model.apply_pre_processed_defaults
|
144
149
|
#
|
145
|
-
# @return [ Array<String ] The names of the non-proc defaults.
|
150
|
+
# @return [ Array<String> ] The names of the non-proc defaults.
|
146
151
|
def apply_pre_processed_defaults
|
147
152
|
pre_processed_defaults.each do |name|
|
148
153
|
apply_default(name)
|
@@ -154,8 +159,9 @@ module Mongoid
|
|
154
159
|
# @example Apply all the proc defaults.
|
155
160
|
# model.apply_post_processed_defaults
|
156
161
|
#
|
157
|
-
# @return [ Array<String ] The names of the proc defaults.
|
162
|
+
# @return [ Array<String> ] The names of the proc defaults.
|
158
163
|
def apply_post_processed_defaults
|
164
|
+
pending_callbacks.delete(:apply_post_processed_defaults)
|
159
165
|
post_processed_defaults.each do |name|
|
160
166
|
apply_default(name)
|
161
167
|
end
|
@@ -184,6 +190,7 @@ module Mongoid
|
|
184
190
|
# @example Apply all the defaults.
|
185
191
|
# model.apply_defaults
|
186
192
|
def apply_defaults
|
193
|
+
pending_callbacks.delete(:apply_defaults)
|
187
194
|
apply_pre_processed_defaults
|
188
195
|
apply_post_processed_defaults
|
189
196
|
end
|
@@ -207,7 +214,7 @@ module Mongoid
|
|
207
214
|
# @example Get the database field name.
|
208
215
|
# model.database_field_name(:authorization)
|
209
216
|
#
|
210
|
-
# @param [ String
|
217
|
+
# @param [ String | Symbol ] name The name to get.
|
211
218
|
#
|
212
219
|
# @return [ String ] The name of the field as it's stored in the db.
|
213
220
|
def database_field_name(name)
|
@@ -222,7 +229,7 @@ module Mongoid
|
|
222
229
|
# @param [ Field ] field The field.
|
223
230
|
# @param [ Object ] value The current value.
|
224
231
|
#
|
225
|
-
# @return [ true
|
232
|
+
# @return [ true | false ] If we set the field lazily.
|
226
233
|
def lazy_settable?(field, value)
|
227
234
|
!frozen? && value.nil? && field.lazy?
|
228
235
|
end
|
@@ -234,11 +241,37 @@ module Mongoid
|
|
234
241
|
# @example Is the document using object ids?
|
235
242
|
# model.using_object_ids?
|
236
243
|
#
|
237
|
-
# @return [ true
|
244
|
+
# @return [ true | false ] Using object ids.
|
238
245
|
def using_object_ids?
|
239
246
|
self.class.using_object_ids?
|
240
247
|
end
|
241
248
|
|
249
|
+
# Does this field start with a dollar sign ($) or contain a dot/period (.)?
|
250
|
+
#
|
251
|
+
# @api private
|
252
|
+
#
|
253
|
+
# @param [ String ] name The field name.
|
254
|
+
#
|
255
|
+
# @return [ true | false ] If this field is dotted or dollared.
|
256
|
+
def dot_dollar_field?(name)
|
257
|
+
n = aliased_fields[name] || name
|
258
|
+
fields.key?(n) && (n.include?('.') || n.start_with?('$'))
|
259
|
+
end
|
260
|
+
|
261
|
+
# Validate whether or not the field starts with a dollar sign ($) or
|
262
|
+
# contains a dot/period (.).
|
263
|
+
#
|
264
|
+
# @api private
|
265
|
+
#
|
266
|
+
# @raise [ InvalidDotDollarAssignment ] If contains dots or starts with a dollar.
|
267
|
+
#
|
268
|
+
# @param [ String ] name The field name.
|
269
|
+
def validate_writable_field_name!(name)
|
270
|
+
if dot_dollar_field?(name)
|
271
|
+
raise Errors::InvalidDotDollarAssignment.new(self.class, name)
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
242
275
|
class << self
|
243
276
|
|
244
277
|
# Stores the provided block to be run when the option name specified is
|
@@ -270,21 +303,64 @@ module Mongoid
|
|
270
303
|
def options
|
271
304
|
@options ||= {}
|
272
305
|
end
|
273
|
-
end
|
274
|
-
|
275
|
-
module ClassMethods
|
276
306
|
|
277
|
-
#
|
307
|
+
# Traverse down the association tree and search for the field for the
|
308
|
+
# given key. To do this, split the key by '.' and for each part (meth) of
|
309
|
+
# the key:
|
278
310
|
#
|
279
|
-
#
|
280
|
-
#
|
311
|
+
# - If the meth is a field, yield the meth, field, and is_field as true.
|
312
|
+
# - If the meth is an association, update the klass to the association's
|
313
|
+
# klass, and yield the meth, klass, and is_field as false.
|
281
314
|
#
|
282
|
-
#
|
283
|
-
#
|
315
|
+
# The next iteration will use klass's fields and associations to continue
|
316
|
+
# traversing the tree.
|
284
317
|
#
|
285
|
-
# @
|
286
|
-
|
287
|
-
|
318
|
+
# @param [ String ] key The key used to search the association tree.
|
319
|
+
# @param [ Hash ] fields The fields to begin the search with.
|
320
|
+
# @param [ Hash ] associations The associations to begin the search with.
|
321
|
+
# @param [ Hash ] aliased_associations The alaised associations to begin
|
322
|
+
# the search with.
|
323
|
+
# @param [ Proc ] block The block takes in three paramaters, the current
|
324
|
+
# meth, the field or the relation, and whether the second parameter is a
|
325
|
+
# field or not.
|
326
|
+
#
|
327
|
+
# @return [ Field ] The field found for the given key at the end of the
|
328
|
+
# search. This will return nil if the last thing found is an association
|
329
|
+
# or no field was found for the given key.
|
330
|
+
#
|
331
|
+
# @api private
|
332
|
+
def traverse_association_tree(key, fields, associations, aliased_associations)
|
333
|
+
klass = nil
|
334
|
+
field = nil
|
335
|
+
key.split('.').each_with_index do |meth, i|
|
336
|
+
fs = i == 0 ? fields : klass&.fields
|
337
|
+
rs = i == 0 ? associations : klass&.relations
|
338
|
+
as = i == 0 ? aliased_associations : klass&.aliased_associations
|
339
|
+
|
340
|
+
# Associations can possibly have two "keys", their name and their alias.
|
341
|
+
# The fields name is what is used to store it in the klass's relations
|
342
|
+
# and field hashes, and the alias is what's used to store that field
|
343
|
+
# in the database. The key inputted to this function is the aliased
|
344
|
+
# key. We can convert them back to their names by looking in the
|
345
|
+
# aliased_associations hash.
|
346
|
+
aliased = meth
|
347
|
+
if as && a = as.fetch(meth, nil)
|
348
|
+
aliased = a.to_s
|
349
|
+
end
|
350
|
+
|
351
|
+
field = nil
|
352
|
+
klass = nil
|
353
|
+
if fs && f = fs[aliased]
|
354
|
+
field = f
|
355
|
+
yield(meth, f, true) if block_given?
|
356
|
+
elsif rs && rel = rs[aliased]
|
357
|
+
klass = rel.klass
|
358
|
+
yield(meth, rel, false) if block_given?
|
359
|
+
else
|
360
|
+
yield(meth, nil, false) if block_given?
|
361
|
+
end
|
362
|
+
end
|
363
|
+
field
|
288
364
|
end
|
289
365
|
|
290
366
|
# Get the name of the provided field as it is stored in the database.
|
@@ -292,16 +368,43 @@ module Mongoid
|
|
292
368
|
# finds aliases for embedded documents and fields, delimited with
|
293
369
|
# period "." character.
|
294
370
|
#
|
295
|
-
#
|
296
|
-
#
|
371
|
+
# Note that this method returns the name of associations as they're
|
372
|
+
# stored in the database, whereas the `relations` hash uses their in-code
|
373
|
+
# aliases. In order to check for membership in the relations hash, you
|
374
|
+
# would first have to look up the string returned from this method in
|
375
|
+
# the aliased_associations hash.
|
297
376
|
#
|
298
|
-
#
|
299
|
-
#
|
377
|
+
# This method will not expand the alias of a belongs_to association that
|
378
|
+
# is not the last item. For example, if we had a School that has_many
|
379
|
+
# Students, and the field name passed was (from the Student's perspective):
|
300
380
|
#
|
301
|
-
#
|
381
|
+
# school._id
|
382
|
+
#
|
383
|
+
# The alias for a belongs_to association is that association's _id field.
|
384
|
+
# Therefore, expanding out this association would yield:
|
385
|
+
#
|
386
|
+
# school_id._id
|
387
|
+
#
|
388
|
+
# This is not the correct field name, because the intention here was not
|
389
|
+
# to get a property of the _id field. The intention was to get a property
|
390
|
+
# of the referenced document. Therefore, if a part of the name passed is
|
391
|
+
# a belongs_to association that is not the last part of the name, we
|
392
|
+
# won't expand its alias, and return:
|
393
|
+
#
|
394
|
+
# school._id
|
395
|
+
#
|
396
|
+
# If the belongs_to association is the last part of the name, we will
|
397
|
+
# pass back the _id field.
|
398
|
+
#
|
399
|
+
# @param [ String | Symbol ] name The name to get.
|
400
|
+
# @param [ Hash ] relations The associations.
|
401
|
+
# @param [ Hash ] alaiased_fields The aliased fields.
|
402
|
+
# @param [ Hash ] alaiased_associations The aliased associations.
|
302
403
|
#
|
303
404
|
# @return [ String ] The name of the field as stored in the database.
|
304
|
-
|
405
|
+
#
|
406
|
+
# @api private
|
407
|
+
def database_field_name(name, relations, aliased_fields, aliased_associations)
|
305
408
|
if Mongoid.broken_alias_handling
|
306
409
|
return nil unless name
|
307
410
|
normalized = name.to_s
|
@@ -310,31 +413,68 @@ module Mongoid
|
|
310
413
|
return nil unless name.present?
|
311
414
|
key = name.to_s
|
312
415
|
segment, remaining = key.split('.', 2)
|
313
|
-
|
416
|
+
|
417
|
+
# Don't get the alias for the field when a belongs_to association
|
418
|
+
# is not the last item. Therefore, get the alias when one of the
|
419
|
+
# following is true:
|
420
|
+
# 1. This is the last item, i.e. there is no remaining.
|
421
|
+
# 2. It is not an association.
|
422
|
+
# 3. It is not a belongs association
|
423
|
+
if !remaining || !relations.key?(segment) || !relations[segment].is_a?(Association::Referenced::BelongsTo)
|
424
|
+
segment = aliased_fields[segment]&.dup || segment
|
425
|
+
end
|
426
|
+
|
314
427
|
return segment unless remaining
|
315
428
|
|
316
429
|
relation = relations[aliased_associations[segment] || segment]
|
317
430
|
if relation
|
318
|
-
|
431
|
+
k = relation.klass
|
432
|
+
"#{segment}.#{database_field_name(remaining, k.relations, k.aliased_fields, k.aliased_associations)}"
|
319
433
|
else
|
320
434
|
"#{segment}.#{remaining}"
|
321
435
|
end
|
322
436
|
end
|
323
437
|
end
|
438
|
+
end
|
439
|
+
|
440
|
+
module ClassMethods
|
441
|
+
|
442
|
+
# Returns an array of names for the attributes available on this object.
|
443
|
+
#
|
444
|
+
# Provides the field names in an ORM-agnostic way. Rails v3.1+ uses this
|
445
|
+
# method to automatically wrap params in JSON requests.
|
446
|
+
#
|
447
|
+
# @example Get the field names
|
448
|
+
# Model.attribute_names
|
449
|
+
#
|
450
|
+
# @return [ Array<String> ] The field names
|
451
|
+
def attribute_names
|
452
|
+
fields.keys
|
453
|
+
end
|
454
|
+
|
455
|
+
# Get the name of the provided field as it is stored in the database.
|
456
|
+
# Used in determining if the field is aliased or not.
|
457
|
+
#
|
458
|
+
# @param [ String | Symbol ] name The name to get.
|
459
|
+
#
|
460
|
+
# @return [ String ] The name of the field as it's stored in the db.
|
461
|
+
def database_field_name(name)
|
462
|
+
Fields.database_field_name(name, relations, aliased_fields, aliased_associations)
|
463
|
+
end
|
324
464
|
|
325
465
|
# Defines all the fields that are accessible on the Document
|
326
466
|
# For each field that is defined, a getter and setter will be
|
327
467
|
# added as an instance method to the Document.
|
328
468
|
#
|
329
469
|
# @example Define a field.
|
330
|
-
# field :score, :
|
470
|
+
# field :score, type: Integer, default: 0
|
331
471
|
#
|
332
472
|
# @param [ Symbol ] name The name of the field.
|
333
473
|
# @param [ Hash ] options The options to pass to the field.
|
334
474
|
#
|
335
|
-
# @option options [ Class ] :type The type of the field.
|
475
|
+
# @option options [ Class | Symbol | String ] :type The type of the field.
|
336
476
|
# @option options [ String ] :label The label for the field.
|
337
|
-
# @option options [ Object
|
477
|
+
# @option options [ Object | Proc ] :default The field's default.
|
338
478
|
#
|
339
479
|
# @return [ Field ] The generated field
|
340
480
|
def field(name, options = {})
|
@@ -367,11 +507,28 @@ module Mongoid
|
|
367
507
|
# @example Does this class use object ids?
|
368
508
|
# person.using_object_ids?
|
369
509
|
#
|
370
|
-
# @return [ true
|
510
|
+
# @return [ true | false ] If the class uses BSON::ObjectIds for the id.
|
371
511
|
def using_object_ids?
|
372
512
|
fields["_id"].object_id_field?
|
373
513
|
end
|
374
514
|
|
515
|
+
# Traverse down the association tree and search for the field for the
|
516
|
+
# given key.
|
517
|
+
#
|
518
|
+
# @param [ String ] key The key used to search the association tree.
|
519
|
+
# @param [ Proc ] block The block takes in three paramaters, the current
|
520
|
+
# meth, the field or the relation, and whether the second parameter is a
|
521
|
+
# field or not.
|
522
|
+
#
|
523
|
+
# @return [ Field ] The field found for the given key at the end of the
|
524
|
+
# search. This will return nil if the last thing found is an association
|
525
|
+
# or no field was found for the given key.
|
526
|
+
#
|
527
|
+
# @api private
|
528
|
+
def traverse_association_tree(key, &block)
|
529
|
+
Fields.traverse_association_tree(key, fields, relations, aliased_associations, &block)
|
530
|
+
end
|
531
|
+
|
375
532
|
protected
|
376
533
|
|
377
534
|
# Add the defaults to the model. This breaks them up between ones that
|
@@ -479,9 +636,7 @@ module Mongoid
|
|
479
636
|
if lazy_settable?(field, raw)
|
480
637
|
write_attribute(name, field.eval_default(self))
|
481
638
|
else
|
482
|
-
|
483
|
-
attribute_will_change!(name) if value.resizable?
|
484
|
-
value
|
639
|
+
process_raw_attribute(name.to_s, raw, field)
|
485
640
|
end
|
486
641
|
end
|
487
642
|
end
|
@@ -573,10 +728,8 @@ module Mongoid
|
|
573
728
|
generated_methods.module_eval do
|
574
729
|
re_define_method("#{meth}_translations=") do |value|
|
575
730
|
attribute_will_change!(name)
|
576
|
-
|
577
|
-
|
578
|
-
field.type.mongoize(_value)
|
579
|
-
end
|
731
|
+
value&.transform_values! do |_value|
|
732
|
+
field.type.mongoize(_value)
|
580
733
|
end
|
581
734
|
attributes[name] = value
|
582
735
|
end
|
@@ -611,20 +764,60 @@ module Mongoid
|
|
611
764
|
|
612
765
|
def field_for(name, options)
|
613
766
|
opts = options.merge(klass: self)
|
614
|
-
|
615
|
-
opts[:type] = type_mapping || unmapped_type(options)
|
767
|
+
opts[:type] = retrieve_and_validate_type(name, options[:type])
|
616
768
|
return Fields::Localized.new(name, opts) if options[:localize]
|
617
769
|
return Fields::ForeignKey.new(name, opts) if options[:identity]
|
618
770
|
Fields::Standard.new(name, opts)
|
619
771
|
end
|
620
772
|
|
621
|
-
|
622
|
-
|
773
|
+
# Get the class for the given type.
|
774
|
+
#
|
775
|
+
# @param [ Symbol ] name The name of the field.
|
776
|
+
# @param [ Symbol | Class ] type The type of the field.
|
777
|
+
#
|
778
|
+
# @return [ Class ] The type of the field.
|
779
|
+
#
|
780
|
+
# @raises [ Mongoid::Errors::InvalidFieldType ] if given an invalid field
|
781
|
+
# type.
|
782
|
+
#
|
783
|
+
# @api private
|
784
|
+
def retrieve_and_validate_type(name, type)
|
785
|
+
result = TYPE_MAPPINGS[type] || unmapped_type(type)
|
786
|
+
raise Errors::InvalidFieldType.new(self, name, type) if !result.is_a?(Class)
|
787
|
+
|
788
|
+
if unsupported_type?(result)
|
789
|
+
warn_message = "Using #{result} as the field type is not supported. "
|
790
|
+
if result == BSON::Decimal128
|
791
|
+
warn_message += 'In BSON <= 4, the BSON::Decimal128 type will work as expected for both storing and querying, but will return a BigDecimal on query in BSON 5+. To use literal BSON::Decimal128 fields with BSON 5, set Mongoid.allow_bson5_decimal128 to true.'
|
792
|
+
else
|
793
|
+
warn_message += 'Saving values of this type to the database will work as expected, however, querying them will return a value of the native Ruby Integer type.'
|
794
|
+
end
|
795
|
+
Mongoid.logger.warn(warn_message)
|
796
|
+
end
|
797
|
+
|
798
|
+
result
|
799
|
+
end
|
800
|
+
|
801
|
+
def unmapped_type(type)
|
802
|
+
if "Boolean" == type.to_s
|
623
803
|
Mongoid::Boolean
|
624
804
|
else
|
625
|
-
|
805
|
+
type || Object
|
626
806
|
end
|
627
807
|
end
|
808
|
+
|
809
|
+
# Queries whether or not the given type is permitted as a declared field
|
810
|
+
# type.
|
811
|
+
#
|
812
|
+
# @param [ Class ] type The type to query
|
813
|
+
#
|
814
|
+
# @return [ true | false ] whether or not the type is supported
|
815
|
+
#
|
816
|
+
# @api private
|
817
|
+
def unsupported_type?(type)
|
818
|
+
return !Mongoid::Config.allow_bson5_decimal128? if type == BSON::Decimal128
|
819
|
+
INVALID_BSON_CLASSES.include?(type)
|
820
|
+
end
|
628
821
|
end
|
629
822
|
end
|
630
823
|
end
|
data/lib/mongoid/findable.rb
CHANGED
@@ -38,12 +38,16 @@ module Mongoid
|
|
38
38
|
:max,
|
39
39
|
:min,
|
40
40
|
:none,
|
41
|
+
:pick,
|
41
42
|
:pluck,
|
42
43
|
:read,
|
43
44
|
:sum,
|
45
|
+
:take,
|
46
|
+
:take!,
|
47
|
+
:tally,
|
44
48
|
:text_search,
|
45
49
|
:update,
|
46
|
-
:update_all
|
50
|
+
:update_all,
|
47
51
|
|
48
52
|
# Returns a count of records in the database.
|
49
53
|
# If you want to specify conditions use where.
|
@@ -72,7 +76,7 @@ module Mongoid
|
|
72
76
|
# @example Are there no saved documents for this model?
|
73
77
|
# Person.empty?
|
74
78
|
#
|
75
|
-
# @return [ true
|
79
|
+
# @return [ true | false ] If the collection is empty.
|
76
80
|
def empty?
|
77
81
|
count == 0
|
78
82
|
end
|
@@ -83,7 +87,7 @@ module Mongoid
|
|
83
87
|
# @example Do any documents exist for the conditions?
|
84
88
|
# Person.exists?
|
85
89
|
#
|
86
|
-
# @return [ true
|
90
|
+
# @return [ true | false ] If any documents exist for the conditions.
|
87
91
|
def exists?
|
88
92
|
with_default_scope.exists?
|
89
93
|
end
|
@@ -118,18 +122,32 @@ module Mongoid
|
|
118
122
|
# strings will be transparently converted to +BSON::ObjectId+ instances
|
119
123
|
# during query construction.
|
120
124
|
#
|
125
|
+
# If this method is given a block, it delegates to +Enumerable#find+ and
|
126
|
+
# returns the first document of those found by the current Crieria object
|
127
|
+
# for which the block returns a truthy value. If both a block and ids are
|
128
|
+
# given, the block is ignored and the documents for the given ids are
|
129
|
+
# returned. If a block and a Proc are given, the method delegates to
|
130
|
+
# +Enumerable#find+ and uses the proc as the default.
|
131
|
+
#
|
121
132
|
# The +find+ method takes into account the default scope defined on the
|
122
133
|
# model class, if any.
|
123
134
|
#
|
124
|
-
# @
|
125
|
-
# array
|
135
|
+
# @note Each argument can be an individual id, an array of ids or
|
136
|
+
# a nested array. Each array will be flattened.
|
137
|
+
#
|
138
|
+
# @param [ Object | Array<Object> ] *args The _id value(s) to find.
|
126
139
|
#
|
127
140
|
# @return [ Document | Array<Document> | nil ] A document or matching documents.
|
128
141
|
#
|
129
142
|
# @raise Errors::DocumentNotFound If not all documents are found and
|
130
143
|
# the +raise_not_found_error+ Mongoid configuration option is truthy.
|
131
|
-
def find(*args)
|
132
|
-
|
144
|
+
def find(*args, &block)
|
145
|
+
empty_or_proc = args.empty? || (args.length == 1 && args.first.is_a?(Proc))
|
146
|
+
if block_given? && empty_or_proc
|
147
|
+
with_default_scope.find(*args, &block)
|
148
|
+
else
|
149
|
+
with_default_scope.find(*args)
|
150
|
+
end
|
133
151
|
end
|
134
152
|
|
135
153
|
# Find the first +Document+ given the conditions.
|
@@ -145,7 +163,7 @@ module Mongoid
|
|
145
163
|
# @raise [ Errors::DocumentNotFound ] If no document found
|
146
164
|
# and Mongoid.raise_not_found_error is true.
|
147
165
|
#
|
148
|
-
# @return [ Document
|
166
|
+
# @return [ Document | nil ] A matching document.
|
149
167
|
def find_by(attrs = {})
|
150
168
|
result = where(attrs).find_first
|
151
169
|
if result.nil? && Mongoid.raise_not_found_error
|
@@ -166,7 +184,6 @@ module Mongoid
|
|
166
184
|
# @raise [ Errors::DocumentNotFound ] If no document found.
|
167
185
|
#
|
168
186
|
# @return [ Document ] A matching document.
|
169
|
-
#
|
170
187
|
def find_by!(attrs = {})
|
171
188
|
result = where(attrs).find_first
|
172
189
|
raise(Errors::DocumentNotFound.new(self, attrs)) unless result
|
@@ -179,9 +196,11 @@ module Mongoid
|
|
179
196
|
# @example Find the first document.
|
180
197
|
# Person.first
|
181
198
|
#
|
199
|
+
# @param [ Integer ] limit The number of documents to return.
|
200
|
+
#
|
182
201
|
# @return [ Document ] The first matching document.
|
183
|
-
def first
|
184
|
-
with_default_scope.first
|
202
|
+
def first(limit = nil)
|
203
|
+
with_default_scope.first(limit)
|
185
204
|
end
|
186
205
|
alias :one :first
|
187
206
|
|
@@ -190,9 +209,11 @@ module Mongoid
|
|
190
209
|
# @example Find the last document.
|
191
210
|
# Person.last
|
192
211
|
#
|
212
|
+
# @param [ Integer ] limit The number of documents to return.
|
213
|
+
#
|
193
214
|
# @return [ Document ] The last matching document.
|
194
|
-
def last
|
195
|
-
with_default_scope.last
|
215
|
+
def last(limit = nil)
|
216
|
+
with_default_scope.last(limit)
|
196
217
|
end
|
197
218
|
end
|
198
219
|
end
|
@@ -27,7 +27,7 @@ module Mongoid
|
|
27
27
|
#
|
28
28
|
# @param [ Specification ] other The spec to compare against.
|
29
29
|
#
|
30
|
-
# @return [ true
|
30
|
+
# @return [ true | false ] If the specs are equal.
|
31
31
|
def ==(other)
|
32
32
|
fields == other.fields && key == other.key
|
33
33
|
end
|
@@ -86,7 +86,7 @@ module Mongoid
|
|
86
86
|
# @api private
|
87
87
|
#
|
88
88
|
# @example Normalize the index options.
|
89
|
-
# specification.normalize_options(
|
89
|
+
# specification.normalize_options(unique: true)
|
90
90
|
#
|
91
91
|
# @param [ Hash ] opts The index options.
|
92
92
|
#
|
@@ -13,7 +13,6 @@ module Mongoid
|
|
13
13
|
:database,
|
14
14
|
:default_language,
|
15
15
|
:language_override,
|
16
|
-
:drop_dups,
|
17
16
|
:name,
|
18
17
|
:sparse,
|
19
18
|
:unique,
|
@@ -29,7 +28,8 @@ module Mongoid
|
|
29
28
|
:text_version,
|
30
29
|
:version,
|
31
30
|
:partial_filter_expression,
|
32
|
-
:collation
|
31
|
+
:collation,
|
32
|
+
:wildcard_projection,
|
33
33
|
]
|
34
34
|
|
35
35
|
VALID_TYPES = [
|
@@ -98,6 +98,10 @@ module Mongoid
|
|
98
98
|
unless VALID_TYPES.include?(value)
|
99
99
|
raise Errors::InvalidIndex.new(klass, spec, options)
|
100
100
|
end
|
101
|
+
|
102
|
+
if value == "geoHaystack"
|
103
|
+
Mongoid::Warnings.warn_geo_haystack_deprecated
|
104
|
+
end
|
101
105
|
end
|
102
106
|
end
|
103
107
|
end
|