mongoid 2.3.5 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +34 -176
- data/LICENSE +1 -1
- data/lib/config/locales/bg.yml +6 -0
- data/lib/config/locales/de.yml +6 -0
- data/lib/config/locales/en-GB.yml +8 -0
- data/lib/config/locales/en.yml +8 -0
- data/lib/config/locales/es.yml +9 -3
- data/lib/config/locales/fr.yml +6 -0
- data/lib/config/locales/hi.yml +6 -0
- data/lib/config/locales/hu.yml +6 -0
- data/lib/config/locales/id.yml +6 -0
- data/lib/config/locales/it.yml +6 -0
- data/lib/config/locales/ja.yml +6 -0
- data/lib/config/locales/kr.yml +6 -0
- data/lib/config/locales/nl.yml +8 -0
- data/lib/config/locales/pl.yml +6 -0
- data/lib/config/locales/pt-BR.yml +6 -0
- data/lib/config/locales/pt.yml +8 -2
- data/lib/config/locales/ro.yml +6 -0
- data/lib/config/locales/ru.yml +6 -0
- data/lib/config/locales/sv.yml +6 -0
- data/lib/config/locales/vi.yml +14 -8
- data/lib/config/locales/zh-CN.yml +6 -0
- data/lib/mongoid/atomic.rb +62 -13
- data/lib/mongoid/atomic/modifiers.rb +33 -1
- data/lib/mongoid/attributes.rb +5 -19
- data/lib/mongoid/callbacks.rb +2 -1
- data/lib/mongoid/collection.rb +2 -2
- data/lib/mongoid/collections/retry.rb +18 -6
- data/lib/mongoid/components.rb +2 -0
- data/lib/mongoid/config.rb +8 -63
- data/lib/mongoid/config/environment.rb +41 -0
- data/lib/mongoid/config/options.rb +74 -0
- data/lib/mongoid/contexts/enumerable.rb +0 -24
- data/lib/mongoid/contexts/mongo.rb +33 -3
- data/lib/mongoid/copyable.rb +1 -1
- data/lib/mongoid/criteria.rb +4 -2
- data/lib/mongoid/criterion/inclusion.rb +1 -16
- data/lib/mongoid/criterion/optional.rb +37 -10
- data/lib/mongoid/criterion/scoping.rb +83 -0
- data/lib/mongoid/criterion/selector.rb +9 -6
- data/lib/mongoid/default_scope.rb +1 -1
- data/lib/mongoid/dirty.rb +163 -29
- data/lib/mongoid/document.rb +58 -7
- data/lib/mongoid/errors.rb +2 -0
- data/lib/mongoid/errors/no_environment.rb +19 -0
- data/lib/mongoid/errors/scope_overwrite.rb +21 -0
- data/lib/mongoid/extensions.rb +6 -0
- data/lib/mongoid/extensions/array/deep_copy.rb +25 -0
- data/lib/mongoid/extensions/hash/deep_copy.rb +25 -0
- data/lib/mongoid/extensions/hash/scoping.rb +1 -1
- data/lib/mongoid/extensions/object/deep_copy.rb +21 -0
- data/lib/mongoid/extensions/proc/scoping.rb +2 -2
- data/lib/mongoid/extensions/symbol/inflections.rb +1 -0
- data/lib/mongoid/fields.rb +171 -104
- data/lib/mongoid/fields/{serializable → internal}/array.rb +33 -1
- data/lib/mongoid/fields/{serializable → internal}/big_decimal.rb +16 -1
- data/lib/mongoid/fields/{serializable → internal}/bignum.rb +1 -1
- data/lib/mongoid/fields/{serializable → internal}/binary.rb +1 -1
- data/lib/mongoid/fields/{serializable → internal}/boolean.rb +16 -1
- data/lib/mongoid/fields/{serializable → internal}/date.rb +1 -1
- data/lib/mongoid/fields/{serializable → internal}/date_time.rb +1 -1
- data/lib/mongoid/fields/{serializable → internal}/fixnum.rb +1 -1
- data/lib/mongoid/fields/{serializable → internal}/float.rb +16 -1
- data/lib/mongoid/fields/internal/foreign_keys/array.rb +74 -0
- data/lib/mongoid/fields/{serializable → internal}/foreign_keys/object.rb +11 -2
- data/lib/mongoid/fields/{serializable → internal}/hash.rb +1 -1
- data/lib/mongoid/fields/{serializable → internal}/integer.rb +16 -1
- data/lib/mongoid/fields/{serializable → internal}/localized.rb +23 -2
- data/lib/mongoid/fields/{serializable → internal}/nil_class.rb +16 -1
- data/lib/mongoid/fields/{serializable → internal}/object.rb +1 -1
- data/lib/mongoid/fields/{serializable → internal}/object_id.rb +16 -1
- data/lib/mongoid/fields/{serializable → internal}/range.rb +21 -2
- data/lib/mongoid/fields/{serializable → internal}/set.rb +16 -1
- data/lib/mongoid/fields/{serializable → internal}/string.rb +16 -1
- data/lib/mongoid/fields/{serializable → internal}/symbol.rb +17 -1
- data/lib/mongoid/fields/{serializable → internal}/time.rb +1 -1
- data/lib/mongoid/fields/{serializable → internal}/time_with_zone.rb +1 -1
- data/lib/mongoid/fields/{serializable → internal}/timekeeping.rb +16 -1
- data/lib/mongoid/fields/mappings.rb +8 -3
- data/lib/mongoid/fields/serializable.rb +34 -3
- data/lib/mongoid/hierarchy.rb +14 -14
- data/lib/mongoid/identity_map.rb +3 -2
- data/lib/mongoid/logger.rb +1 -7
- data/lib/mongoid/named_scope.rb +16 -12
- data/lib/mongoid/observer.rb +5 -1
- data/lib/mongoid/paranoia.rb +1 -0
- data/lib/mongoid/persistence.rb +11 -4
- data/lib/mongoid/persistence/atomic.rb +4 -1
- data/lib/mongoid/persistence/atomic/add_to_set.rb +17 -1
- data/lib/mongoid/persistence/atomic/sets.rb +1 -1
- data/lib/mongoid/railties/database.rake +1 -1
- data/lib/mongoid/relations.rb +1 -3
- data/lib/mongoid/relations/auto_save.rb +1 -1
- data/lib/mongoid/relations/builders.rb +1 -1
- data/lib/mongoid/relations/builders/embedded/many.rb +2 -6
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +1 -1
- data/lib/mongoid/relations/builders/nested_attributes/one.rb +1 -1
- data/lib/mongoid/relations/builders/referenced/many_to_many.rb +1 -1
- data/lib/mongoid/relations/cascading/delete.rb +1 -1
- data/lib/mongoid/relations/cyclic.rb +10 -6
- data/lib/mongoid/relations/embedded/atomic.rb +3 -3
- data/lib/mongoid/relations/embedded/many.rb +98 -20
- data/lib/mongoid/relations/macros.rb +2 -0
- data/lib/mongoid/relations/many.rb +13 -0
- data/lib/mongoid/relations/metadata.rb +3 -3
- data/lib/mongoid/relations/nested_builder.rb +4 -3
- data/lib/mongoid/relations/proxy.rb +0 -1
- data/lib/mongoid/relations/referenced/batch.rb +3 -2
- data/lib/mongoid/relations/referenced/in.rb +3 -3
- data/lib/mongoid/relations/referenced/many.rb +89 -10
- data/lib/mongoid/relations/referenced/many_to_many.rb +34 -43
- data/lib/mongoid/relations/referenced/one.rb +8 -4
- data/lib/mongoid/relations/synchronization.rb +22 -5
- data/lib/mongoid/threaded.rb +38 -276
- data/lib/mongoid/threaded/lifecycle.rb +18 -18
- data/lib/mongoid/timestamps/updated.rb +13 -3
- data/lib/mongoid/validations.rb +22 -1
- data/lib/mongoid/validations/presence.rb +40 -0
- data/lib/mongoid/validations/uniqueness.rb +14 -3
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid/versioning.rb +6 -2
- data/lib/rails/mongoid.rb +7 -1
- metadata +64 -45
- data/lib/mongoid/fields/serializable/foreign_keys/array.rb +0 -42
- data/lib/mongoid/relations/embedded/sort.rb +0 -31
@@ -1,42 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module Mongoid #:nodoc:
|
3
|
-
module Fields #:nodoc:
|
4
|
-
module Serializable #:nodoc:
|
5
|
-
module ForeignKeys #:nodoc:
|
6
|
-
|
7
|
-
# Defines the behaviour for array fields.
|
8
|
-
class Array
|
9
|
-
include Serializable
|
10
|
-
|
11
|
-
# Is the field a BSON::ObjectId?
|
12
|
-
#
|
13
|
-
# @example Is the field a BSON::ObjectId?
|
14
|
-
# field.object_id_field?
|
15
|
-
#
|
16
|
-
# @return [ true, false ] If the field is a BSON::ObjectId.
|
17
|
-
#
|
18
|
-
# @since 2.2.0
|
19
|
-
def object_id_field?
|
20
|
-
@object_id_field ||=
|
21
|
-
metadata.polymorphic? ? true : metadata.klass.using_object_ids?
|
22
|
-
end
|
23
|
-
|
24
|
-
# Serialize the object from the type defined in the model to a MongoDB
|
25
|
-
# compatible object to store.
|
26
|
-
#
|
27
|
-
# @example Serialize the field.
|
28
|
-
# field.serialize(object)
|
29
|
-
#
|
30
|
-
# @param [ Object ] object The object to cast.
|
31
|
-
#
|
32
|
-
# @return [ Array ] The converted object.
|
33
|
-
#
|
34
|
-
# @since 2.1.0
|
35
|
-
def serialize(object)
|
36
|
-
object ? constraint.convert(object) : []
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module Mongoid # :nodoc:
|
3
|
-
module Relations #:nodoc:
|
4
|
-
module Embedded #:nodoc:
|
5
|
-
|
6
|
-
# This module handles embedded associations sorting
|
7
|
-
# Since mongodb doesn't have virtual collection for embedded docs yet
|
8
|
-
# (see https://jira.mongodb.org/browse/SERVER-142 for details)
|
9
|
-
# Sorting implemented in ruby
|
10
|
-
# This can be a performance killer on collections with many embedded documents
|
11
|
-
module Sort
|
12
|
-
|
13
|
-
# Sorts documents
|
14
|
-
#
|
15
|
-
# @param [ Array<Documents> ] documents array of documents
|
16
|
-
# @param [ Mongoid::Relations::Metadata ] metadata association metadata
|
17
|
-
def sort_documents!(documents, metadata)
|
18
|
-
sort_options = Criteria.new(metadata.klass).order_by(metadata.order).options[:sort]
|
19
|
-
|
20
|
-
docs = documents.sort_by do |document|
|
21
|
-
sort_options.map do |key, direction|
|
22
|
-
Contexts::Enumerable::Sort.new(document.read_attribute(key), direction)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
documents.replace(docs)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|