mongoid 2.0.0.rc.6 → 2.0.0.rc.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -2
- data/lib/config/locales/bg.yml +3 -6
- data/lib/config/locales/de.yml +2 -5
- data/lib/config/locales/en.yml +2 -5
- data/lib/config/locales/es.yml +2 -5
- data/lib/config/locales/fr.yml +2 -5
- data/lib/config/locales/hu.yml +2 -5
- data/lib/config/locales/it.yml +2 -5
- data/lib/config/locales/kr.yml +2 -5
- data/lib/config/locales/nl.yml +2 -5
- data/lib/config/locales/pl.yml +2 -5
- data/lib/config/locales/pt-br.yml +2 -5
- data/lib/config/locales/pt.yml +2 -5
- data/lib/config/locales/ro.yml +2 -5
- data/lib/config/locales/ru.yml +41 -0
- data/lib/config/locales/sv.yml +2 -5
- data/lib/config/locales/zh-CN.yml +3 -6
- data/lib/mongoid/atomicity.rb +2 -2
- data/lib/mongoid/attributes.rb +40 -69
- data/lib/mongoid/attributes/processing.rb +142 -0
- data/lib/mongoid/collections.rb +1 -0
- data/lib/mongoid/components.rb +1 -1
- data/lib/mongoid/config.rb +0 -1
- data/lib/mongoid/contexts/mongo.rb +13 -9
- data/lib/mongoid/criteria.rb +15 -1
- data/lib/mongoid/criterion/inclusion.rb +36 -11
- data/lib/mongoid/criterion/inspection.rb +3 -1
- data/lib/mongoid/criterion/optional.rb +2 -2
- data/lib/mongoid/dirty.rb +1 -0
- data/lib/mongoid/document.rb +11 -5
- data/lib/mongoid/extensions/integer/conversions.rb +2 -2
- data/lib/mongoid/extensions/object_id/conversions.rb +62 -32
- data/lib/mongoid/field.rb +5 -2
- data/lib/mongoid/identity.rb +2 -1
- data/lib/mongoid/matchers.rb +5 -32
- data/lib/mongoid/matchers/default.rb +53 -10
- data/lib/mongoid/matchers/or.rb +30 -0
- data/lib/mongoid/matchers/strategies.rb +63 -0
- data/lib/mongoid/multi_parameter_attributes.rb +4 -2
- data/lib/mongoid/nested_attributes.rb +8 -0
- data/lib/mongoid/persistence.rb +2 -1
- data/lib/mongoid/persistence/insert.rb +3 -3
- data/lib/mongoid/persistence/insert_embedded.rb +2 -1
- data/lib/mongoid/relations.rb +2 -1
- data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +4 -2
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +2 -0
- data/lib/mongoid/relations/cascading.rb +1 -1
- data/lib/mongoid/relations/cascading/nullify.rb +1 -1
- data/lib/mongoid/relations/constraint.rb +42 -0
- data/lib/mongoid/relations/cyclic.rb +6 -0
- data/lib/mongoid/relations/embedded/many.rb +4 -4
- data/lib/mongoid/relations/macros.rb +1 -1
- data/lib/mongoid/relations/many.rb +1 -0
- data/lib/mongoid/relations/metadata.rb +12 -4
- data/lib/mongoid/relations/nested_builder.rb +1 -3
- data/lib/mongoid/relations/referenced/many.rb +11 -18
- data/lib/mongoid/relations/referenced/many_to_many.rb +19 -32
- data/lib/mongoid/relations/referenced/one.rb +3 -1
- data/lib/mongoid/timestamps.rb +1 -1
- data/lib/mongoid/validations/associated.rb +11 -9
- data/lib/mongoid/validations/uniqueness.rb +1 -1
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid/versioning.rb +2 -2
- metadata +9 -4
data/Rakefile
CHANGED
@@ -32,8 +32,8 @@ Rspec::Core::RakeTask.new("spec:unit") do |spec|
|
|
32
32
|
spec.pattern = "spec/unit/**/*_spec.rb"
|
33
33
|
end
|
34
34
|
|
35
|
-
Rspec::Core::RakeTask.new("spec:
|
36
|
-
spec.pattern = "spec/
|
35
|
+
Rspec::Core::RakeTask.new("spec:functional") do |spec|
|
36
|
+
spec.pattern = "spec/functional/**/*_spec.rb"
|
37
37
|
end
|
38
38
|
|
39
39
|
Rspec::Core::RakeTask.new('spec:progress') do |spec|
|
data/lib/config/locales/bg.yml
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
bg:
|
2
|
-
activemodel:
|
3
|
-
errors:
|
4
|
-
messages:
|
5
|
-
taken: е вече заето
|
6
|
-
|
7
2
|
mongoid:
|
8
3
|
errors:
|
9
4
|
messages:
|
5
|
+
taken:
|
6
|
+
е вече заето
|
10
7
|
document_not_found:
|
11
8
|
Не е намерен документ %{klass} с id(та) %{identifiers}.
|
12
9
|
invalid_database:
|
@@ -29,7 +26,7 @@ bg:
|
|
29
26
|
Присвояването на вложини атрибути за %{association} е
|
30
27
|
ограничено до %{limit} записа
|
31
28
|
embedded_in_must_have_inverse_of:
|
32
|
-
Опциите на embedded_in асоциацията трябва да съдържат
|
29
|
+
Опциите на embedded_in асоциацията трябва да съдържат inverse_of.
|
33
30
|
dependent_only_references_one_or_many:
|
34
31
|
Опцията dependent => destroy|delete, която е посочена е
|
35
32
|
валидна само за references_one или references_many връзки
|
data/lib/config/locales/de.yml
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
de:
|
2
|
-
activemodel:
|
3
|
-
errors:
|
4
|
-
messages:
|
5
|
-
taken: ist bereits vergeben
|
6
|
-
|
7
2
|
mongoid:
|
8
3
|
errors:
|
9
4
|
messages:
|
5
|
+
taken:
|
6
|
+
ist bereits vergeben
|
10
7
|
document_not_found:
|
11
8
|
Dokument für Klasse %{klass} mit ID(s) %{identifiers} nicht gefunden.
|
12
9
|
invalid_database:
|
data/lib/config/locales/en.yml
CHANGED
data/lib/config/locales/es.yml
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
es:
|
2
|
-
activemodel:
|
3
|
-
errors:
|
4
|
-
messages:
|
5
|
-
taken: ya está en uso
|
6
|
-
|
7
2
|
mongoid:
|
8
3
|
errors:
|
9
4
|
messages:
|
5
|
+
taken:
|
6
|
+
ya está en uso
|
10
7
|
document_not_found:
|
11
8
|
No se encontró ningún documento para la clase %{klass} con los id(s) %{identifiers}.
|
12
9
|
invalid_database:
|
data/lib/config/locales/fr.yml
CHANGED
data/lib/config/locales/hu.yml
CHANGED
data/lib/config/locales/it.yml
CHANGED
data/lib/config/locales/kr.yml
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
kr:
|
2
|
-
activemodel:
|
3
|
-
errors:
|
4
|
-
messages:
|
5
|
-
taken: 이미 사용하고있습니다 #is already taken
|
6
|
-
|
7
2
|
mongoid:
|
8
3
|
errors:
|
9
4
|
messages:
|
5
|
+
taken:
|
6
|
+
이미 사용하고있습니다 #is already taken
|
10
7
|
document_not_found:
|
11
8
|
클라스 %{klass}와 id를 %{identifiers} 위한 문서를 찾을수 없습니다.
|
12
9
|
#Document not found for class %{klass} with id(s) %{identifiers}.
|
data/lib/config/locales/nl.yml
CHANGED
data/lib/config/locales/pl.yml
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
pt-br:
|
2
|
-
activemodel:
|
3
|
-
errors:
|
4
|
-
messages:
|
5
|
-
taken: já está utilizada
|
6
|
-
|
7
2
|
mongoid:
|
8
3
|
errors:
|
9
4
|
messages:
|
5
|
+
taken:
|
6
|
+
já está utilizada
|
10
7
|
document_not_found:
|
11
8
|
Nenhum documento encontrado para a classe %{klass} com os id(s) %{identifiers}.
|
12
9
|
invalid_database:
|
data/lib/config/locales/pt.yml
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
pt:
|
2
|
-
activemodel:
|
3
|
-
errors:
|
4
|
-
messages:
|
5
|
-
taken: já está utilizada
|
6
|
-
|
7
2
|
mongoid:
|
8
3
|
errors:
|
9
4
|
messages:
|
5
|
+
taken:
|
6
|
+
já está utilizada
|
10
7
|
document_not_found:
|
11
8
|
Nenhum documento encontrado para a classe %{klass} com os id(s) %{identifiers}.
|
12
9
|
invalid_database:
|
data/lib/config/locales/ro.yml
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
ru:
|
2
|
+
mongoid:
|
3
|
+
errors:
|
4
|
+
messages:
|
5
|
+
taken:
|
6
|
+
уже занят
|
7
|
+
document_not_found:
|
8
|
+
Документ класса %{klass} с id %{identifiers} не найден.
|
9
|
+
invalid_database:
|
10
|
+
База данных должная быть Mongo::DB, а не %{name}.
|
11
|
+
invalid_type:
|
12
|
+
Поле уже было определено в классе %{klass}, но получено как %{other}
|
13
|
+
со значением %{value}.
|
14
|
+
unsupported_version:
|
15
|
+
Версия MongoDB %{version} не поддерживается. Пожалуйста, обновитесь до
|
16
|
+
версии %{mongo_version}.
|
17
|
+
validations:
|
18
|
+
Документ не прошёл валидацию - %{errors}.
|
19
|
+
invalid_collection:
|
20
|
+
Доступ к коллекции для класса %{klass} запрещён, так как это вложенный
|
21
|
+
документ. Пожалуйста, обратитесь к коллекции через родительский документ.
|
22
|
+
invalid_field:
|
23
|
+
Определение поля с именем %{name} запрещено. Не определяйте поля
|
24
|
+
с именами совпадающими с внутренними атрибутами или методами Mongoid.
|
25
|
+
Используйте Document#instance_methods для просмотра запрещённых имён.
|
26
|
+
too_many_nested_attribute_records:
|
27
|
+
Accepting nested attributes для %{association} ограничено
|
28
|
+
%{limit} записями.
|
29
|
+
embedded_in_must_have_inverse_of:
|
30
|
+
Указание опции inverse_of для embedded_in ассоциации обязательно.
|
31
|
+
dependent_only_references_one_or_many:
|
32
|
+
Опция dependent => destroy|delete доступная только для
|
33
|
+
references_one или references_many ассоциаций.
|
34
|
+
association_cant_have_inverse_of:
|
35
|
+
Опция inverse_of не может использоваться с этой ассоциацией.
|
36
|
+
Используйте её с embedded_in или references_many ассоциациями.
|
37
|
+
calling_document_find_with_nil_is_invalid:
|
38
|
+
Вызов Document#find с nil запрещён
|
39
|
+
unsaved_document:
|
40
|
+
Вызов методов create или create! запрещён у реляционной ассоциации
|
41
|
+
(%{document}), у которой родитель (%{base}) не сохранён.
|
data/lib/config/locales/sv.yml
CHANGED
data/lib/mongoid/atomicity.rb
CHANGED
@@ -81,7 +81,7 @@ module Mongoid #:nodoc:
|
|
81
81
|
#
|
82
82
|
# @return [ Hash ] The $pushAll operations.
|
83
83
|
def _pushes
|
84
|
-
pushable? ? { _path =>
|
84
|
+
pushable? ? { _path => as_document } : {}
|
85
85
|
end
|
86
86
|
|
87
87
|
# Determine if the document can be pushed.
|
@@ -104,7 +104,7 @@ module Mongoid #:nodoc:
|
|
104
104
|
if changed? && !new_record?
|
105
105
|
setters
|
106
106
|
else
|
107
|
-
embedded_one? && new_record? ? { _path =>
|
107
|
+
embedded_one? && new_record? ? { _path => as_document } : {}
|
108
108
|
end
|
109
109
|
end
|
110
110
|
end
|
data/lib/mongoid/attributes.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
require "mongoid/attributes/processing"
|
3
|
+
|
2
4
|
module Mongoid #:nodoc:
|
3
5
|
|
4
6
|
# This module contains the logic for handling the internal attributes hash,
|
5
7
|
# and how to get and set values.
|
6
8
|
module Attributes
|
9
|
+
include Processing
|
7
10
|
|
8
11
|
# Returns the object type. This corresponds to the name of the class that
|
9
12
|
# this document is, which is used in determining the class to
|
@@ -13,6 +16,8 @@ module Mongoid #:nodoc:
|
|
13
16
|
# person._type
|
14
17
|
#
|
15
18
|
# @return [ String ] The name of the class the document is.
|
19
|
+
#
|
20
|
+
# @since 1.0.0
|
16
21
|
def _type
|
17
22
|
@attributes["_type"]
|
18
23
|
end
|
@@ -25,6 +30,8 @@ module Mongoid #:nodoc:
|
|
25
30
|
# @param [ String ] new_type The name of the class.
|
26
31
|
#
|
27
32
|
# @return [ String ] the new type.
|
33
|
+
#
|
34
|
+
# @since 1.0.0
|
28
35
|
def _type=(new_type)
|
29
36
|
@attributes["_type"] = new_type
|
30
37
|
end
|
@@ -37,6 +44,8 @@ module Mongoid #:nodoc:
|
|
37
44
|
# @param [ String, Symbol ] name The name of the attribute.
|
38
45
|
#
|
39
46
|
# @return [ true, false ] True if present, false if not.
|
47
|
+
#
|
48
|
+
# @since 1.0.0
|
40
49
|
def attribute_present?(name)
|
41
50
|
!read_attribute(name).blank?
|
42
51
|
end
|
@@ -48,6 +57,8 @@ module Mongoid #:nodoc:
|
|
48
57
|
# person.id
|
49
58
|
#
|
50
59
|
# @return [ BSON::ObjectId, String ] The id of the document.
|
60
|
+
#
|
61
|
+
# @since 1.0.0
|
51
62
|
def id
|
52
63
|
@attributes["_id"]
|
53
64
|
end
|
@@ -61,50 +72,13 @@ module Mongoid #:nodoc:
|
|
61
72
|
# @param [ BSON::ObjectId, String ] new_id The new id.
|
62
73
|
#
|
63
74
|
# @return [ BSON::ObjectId, String ] The new id.
|
75
|
+
#
|
76
|
+
# @since 1.0.0
|
64
77
|
def id=(new_id)
|
65
78
|
@attributes["_id"] = _id_type.set(new_id)
|
66
79
|
end
|
67
80
|
alias :_id= :id=
|
68
81
|
|
69
|
-
# Used for allowing accessor methods for dynamic attributes.
|
70
|
-
#
|
71
|
-
# @param [ String, Symbol ] name The name of the method.
|
72
|
-
# @param [ Array ] *args The arguments to the method.
|
73
|
-
def method_missing(name, *args)
|
74
|
-
attr = name.to_s
|
75
|
-
return super unless @attributes.has_key?(attr.reader)
|
76
|
-
if attr.writer?
|
77
|
-
# "args.size > 1" allows to simulate 1.8 behavior of "*args"
|
78
|
-
write_attribute(attr.reader, (args.size > 1) ? args : args.first)
|
79
|
-
else
|
80
|
-
read_attribute(attr.reader)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
# Process the provided attributes casting them to their proper values if a
|
85
|
-
# field exists for them on the document. This will be limited to only the
|
86
|
-
# attributes provided in the suppied +Hash+ so that no extra nil values get
|
87
|
-
# put into the document's attributes.
|
88
|
-
#
|
89
|
-
# @example Process the attributes.
|
90
|
-
# person.process(:title => "sir", :age => 40)
|
91
|
-
#
|
92
|
-
# @param [ Hash ] attrs The attributes to set.
|
93
|
-
def process(attrs = nil)
|
94
|
-
pending = {}
|
95
|
-
sanitize_for_mass_assignment(attrs || {}).each_pair do |key, value|
|
96
|
-
if set_allowed?(key)
|
97
|
-
write_attribute(key, value)
|
98
|
-
else
|
99
|
-
pending[key.to_s] = value and next if relations.has_key?(key.to_s)
|
100
|
-
send("#{key}=", value)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
yield self if block_given?
|
104
|
-
process_relations(pending)
|
105
|
-
setup_modifications
|
106
|
-
end
|
107
|
-
|
108
82
|
# Read a value from the document attributes. If the value does not exist
|
109
83
|
# it will return nil.
|
110
84
|
#
|
@@ -117,6 +91,8 @@ module Mongoid #:nodoc:
|
|
117
91
|
# @param [ String, Symbol ] name The name of the attribute to get.
|
118
92
|
#
|
119
93
|
# @return [ Object ] The value of the attribute.
|
94
|
+
#
|
95
|
+
# @since 1.0.0
|
120
96
|
def read_attribute(name)
|
121
97
|
access = name.to_s
|
122
98
|
value = @attributes[access]
|
@@ -132,6 +108,8 @@ module Mongoid #:nodoc:
|
|
132
108
|
# person.remove_attribute(:title)
|
133
109
|
#
|
134
110
|
# @param [ String, Symbol ] name The name of the attribute to remove.
|
111
|
+
#
|
112
|
+
# @since 1.0.0
|
135
113
|
def remove_attribute(name)
|
136
114
|
access = name.to_s
|
137
115
|
modify(access, @attributes.delete(name.to_s), nil)
|
@@ -145,6 +123,8 @@ module Mongoid #:nodoc:
|
|
145
123
|
# @param [ Array ] *args The name of the method.
|
146
124
|
#
|
147
125
|
# @return [ true, false ] True if it does, false if not.
|
126
|
+
#
|
127
|
+
# @since 1.0.0
|
148
128
|
def respond_to?(*args)
|
149
129
|
(Mongoid.allow_dynamic_fields &&
|
150
130
|
@attributes &&
|
@@ -164,6 +144,8 @@ module Mongoid #:nodoc:
|
|
164
144
|
#
|
165
145
|
# @param [ String, Symbol ] name The name of the attribute to update.
|
166
146
|
# @param [ Object ] value The value to set for the attribute.
|
147
|
+
#
|
148
|
+
# @since 1.0.0
|
167
149
|
def write_attribute(name, value)
|
168
150
|
access = name.to_s
|
169
151
|
modify(access, @attributes[access], typed_value_for(access, value))
|
@@ -181,10 +163,11 @@ module Mongoid #:nodoc:
|
|
181
163
|
# person.attributes = { :title => "Mr." }
|
182
164
|
#
|
183
165
|
# @param [ Hash ] attrs The new attributes to set.
|
166
|
+
#
|
167
|
+
# @since 1.0.0
|
184
168
|
def write_attributes(attrs = nil)
|
185
|
-
process(attrs
|
186
|
-
|
187
|
-
identify
|
169
|
+
process(attrs) do |document|
|
170
|
+
document.identify if new? && id.blank?
|
188
171
|
end
|
189
172
|
end
|
190
173
|
alias :attributes= :write_attributes
|
@@ -197,6 +180,8 @@ module Mongoid #:nodoc:
|
|
197
180
|
# person.default_attributes
|
198
181
|
#
|
199
182
|
# @return [ Hash ] The default values for each field.
|
183
|
+
#
|
184
|
+
# @since 1.0.0
|
200
185
|
def default_attributes
|
201
186
|
default_values = defaults
|
202
187
|
default_values.each_pair do |key, val|
|
@@ -205,34 +190,18 @@ module Mongoid #:nodoc:
|
|
205
190
|
default_values || {}
|
206
191
|
end
|
207
192
|
|
208
|
-
#
|
209
|
-
# to fire off.
|
210
|
-
#
|
211
|
-
# @example Process the relations.
|
212
|
-
# document.process_relations({ "addressable" => person })
|
213
|
-
#
|
214
|
-
# @param [ Hash ] pending The pending relation values.
|
215
|
-
def process_relations(pending)
|
216
|
-
pending.each_pair do |name, value|
|
217
|
-
metadata = relations[name]
|
218
|
-
if value.is_a?(Hash)
|
219
|
-
metadata.nested_builder(value, {}).build(self)
|
220
|
-
else
|
221
|
-
send("#{name}=", value, :binding => true)
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
# Return true if dynamic field setting is enabled.
|
227
|
-
#
|
228
|
-
# @example Is a set allowed for this name?
|
229
|
-
# person.set_allowed?(:title)
|
230
|
-
#
|
231
|
-
# @param [ String, Symbol ] key The name of the field.
|
193
|
+
# Used for allowing accessor methods for dynamic attributes.
|
232
194
|
#
|
233
|
-
# @
|
234
|
-
|
235
|
-
|
195
|
+
# @param [ String, Symbol ] name The name of the method.
|
196
|
+
# @param [ Array ] *args The arguments to the method.
|
197
|
+
def method_missing(name, *args)
|
198
|
+
attr = name.to_s
|
199
|
+
return super unless @attributes.has_key?(attr.reader)
|
200
|
+
if attr.writer?
|
201
|
+
write_attribute(attr.reader, (args.size > 1) ? args : args.first)
|
202
|
+
else
|
203
|
+
read_attribute(attr.reader)
|
204
|
+
end
|
236
205
|
end
|
237
206
|
|
238
207
|
# Return the typecasted value for a field.
|
@@ -244,6 +213,8 @@ module Mongoid #:nodoc:
|
|
244
213
|
# @param [ Object ] value The uncast value.
|
245
214
|
#
|
246
215
|
# @return [ Object ] The cast value.
|
216
|
+
#
|
217
|
+
# @since 1.0.0
|
247
218
|
def typed_value_for(key, value)
|
248
219
|
fields.has_key?(key) ? fields[key].set(value) : value
|
249
220
|
end
|