mongoid 2.0.0.beta.18 → 2.0.0.beta.19

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,42 @@
1
+ bg:
2
+ activemodel:
3
+ errors:
4
+ messages:
5
+ taken: е вече заето
6
+
7
+ mongoid:
8
+ errors:
9
+ messages:
10
+ document_not_found:
11
+ Не е намерен документ %{klass} с id(та) %{identifiers}.
12
+ invalid_database:
13
+ Базата данни трябва да е от тип Mnogo:DB, а не %{name}.
14
+ invalid_type:
15
+ Полето е дефинирано като a(n) %{klass}, но се присвоява %{other}
16
+ със стойност %{value}.
17
+ unsupported_version:
18
+ MongoDB %{version} не се подържа, моля ползвайте версия след %{mongo_version}.
19
+ validations:
20
+ Неуспешна валидация - %{errors} грешки.
21
+ invalid_collection:
22
+ Достъпа до колекцията за %{klass} не е разрешена, тъй като
23
+ тя е вложен документ, можете да я достъпите през главният документ
24
+ invalid_field:
25
+ Дефинирането на поле с име %{name} не е разрешено. Не дефинирайте
26
+ полета, които са в конфликт с Mongoid вътрешните атрибути.
27
+ Можете да ги видите с Document#instance_methods
28
+ too_many_nested_attribute_records:
29
+ Присвояването на вложини атрибути за %{association} е
30
+ ограничено до %{limit} записа
31
+ embedded_in_must_have_inverse_of:
32
+ Опциите на embedded_in асоциацията трябва да съдържат invers_of.
33
+ dependent_only_references_one_or_many:
34
+ Опцията dependent => destroy|delete, която е посочена е
35
+ валидна само за references_one или references_many връзки
36
+ association_cant_have_inverse_of:
37
+ Дефинирането на inverse_of за тази асоциация не е позволено.
38
+ Използвайте тази опция само за embedded_in или
39
+ references_many като масив.
40
+ calling_document_find_with_nil_is_invalid:
41
+ Извикването на Document#find със nil е невалидно
42
+
@@ -0,0 +1,41 @@
1
+ de:
2
+ activemodel:
3
+ errors:
4
+ messages:
5
+ taken: ist bereits vergeben
6
+
7
+ mongoid:
8
+ errors:
9
+ messages:
10
+ document_not_found:
11
+ Dokument für Klasse %{klass} mit ID(s) %{identifiers} nicht gefunden.
12
+ invalid_database:
13
+ Datenbank sollte eine Mongo::DB sein, nicht %{name}.
14
+ invalid_type:
15
+ Feld wurde als a(n) %{klass} definiert, doch der Wert %{value} vom Typ
16
+ %{other} wurde übergeben.
17
+ unsupported_version:
18
+ MongoDB %{version} wird nicht unterstützt, bitte auf Version
19
+ %{mongo_version} aktualisieren.
20
+ validations:
21
+ Validierung fehlgeschlagen - %{errors}.
22
+ invalid_collection:
23
+ Zugriff auf die Collection von %{klass} ist nicht erlaubt,
24
+ da es sich um ein eingebettetes Dokument handelt. Auf die Collection
25
+ kann vom Wurzeldokument aus zugegriffen werden.
26
+ invalid_field:
27
+ Das Feld %{name} kann nicht definiert werden, da sein Name mit
28
+ einem internen Mongoid-Attribut oder Methodennamen kollidiert.
29
+ Siehe Document#instance_methods für eine Auflistung dieser Namen.
30
+ too_many_nested_attribute_records:
31
+ Verschachtelte Attribute für %{association} sind auf %{limit} Einträge
32
+ beschränkt.
33
+ embedded_in_must_have_inverse_of:
34
+ Die Optionen für eine embedded_in-Beziehung müssen inverse_of beinhalten.
35
+ dependent_only_references_one_or_many:
36
+ Die dependent => destroy|delete-Option ist nur für
37
+ references_one oder references_many-Beziehungen gültig.
38
+ association_cant_have_inverse_of:
39
+ Es ist nicht erlaubt, inverse_of für diese Beziehung zu definieren.
40
+ Diese Option kann nur für embedded_in oder references_many als Array
41
+ verwendet werden.
@@ -38,3 +38,5 @@ en:
38
38
  association_cant_have_inverse_of:
39
39
  Defining an inverse_of on this association is not allowed. Only
40
40
  use this option on embedded_in or references_many as array.
41
+ calling_document_find_with_nil_is_invalid:
42
+ Calling Document#find with nil is invalid
@@ -0,0 +1,45 @@
1
+ hu:
2
+ activemodel:
3
+ errors:
4
+ messages:
5
+ taken: már foglalt
6
+
7
+ mongoid:
8
+ errors:
9
+ messages:
10
+ document_not_found:
11
+ %{klass} osztályban, %{identifiers} id(k)-el nem található dokumentum.
12
+ invalid_database:
13
+ Az adatbázisnak Mongo::DB-nek kellene lennie, nem %{name}.
14
+ invalid_type:
15
+ A mező %{klass} -ként volt meghatározva, de a kapott érték %{value}
16
+ egy %{other}.
17
+ unsupported_version:
18
+ MongoDB %{version} nem támogatott, kérjük frissítsen
19
+ a %{mongo_version} verzióra.
20
+ validations:
21
+ Érvénytelen - %{errors}.
22
+ invalid_collection:
23
+ %{klass} osztálybeli kollekcióhoz való hozzáférés nem engedélyezett,
24
+ mivel egy beágyazott dokumentum. A kollekció a gyökér dokumentumból
25
+ érhető el.
26
+ invalid_field:
27
+ %{name} mező név nem engedélyezett, mivel a Mongoid által használt
28
+ belső tulajdonság vagy eljárás névvel eggyezik. Használja a
29
+ Document#instance_methods parancsot ezen nevek lekérdezéséhez.
30
+ too_many_nested_attribute_records:
31
+ %{association} esetében a beágyazott tulajdonságok %{limit} számú
32
+ bejegyzésre elfogadhatóak.
33
+ embedded_in_must_have_inverse_of:
34
+ Az embedded_in tipusú kapcsolat esetében kötelező az inverse_of
35
+ opció használata.
36
+ dependent_only_references_one_or_many:
37
+ A dependent => destroy|delete opció csak a references_one vagy
38
+ references_many kapcsolatok esetében érvényes.
39
+ association_cant_have_inverse_of:
40
+ Ezen a tipusú kapcsolaton az inverse_of opció érvénytelen, csak
41
+ az embedded_in vagy references_many as array tipusú kapcsolatok
42
+ esetében használható.
43
+ calling_document_find_with_nil_is_invalid:
44
+ Document#find parancs nil érték esetében érvénytelen.
45
+
@@ -0,0 +1,47 @@
1
+ en:
2
+ activemodel:
3
+ errors:
4
+ messages:
5
+ taken: este deja folosit
6
+
7
+ mongoid:
8
+ errors:
9
+ messages:
10
+ document_not_found:
11
+ Nu există document în clasa %{klass} cu id %{identifiers}.
12
+ invalid_database:
13
+ Baza de date ar trebui să fie de tipul Mongo::DB, nu %{name}.
14
+ invalid_type:
15
+ Câmpul a fost definit ca şi un(o) %{klass}, dar valoarea
16
+ recepţionată %{value} este de clasa %{other}.
17
+ unsupported_version:
18
+ Versiunea MongoDB %{version} nu este suportată.
19
+ Vă rugăm să folosiţi versiunea %{mongo_version}.
20
+ validations:
21
+ Validare nereuşită - %{errors}.
22
+ invalid_collection:
23
+ Accesul la colecţie din clasa %{klass} este interzisă, fiindcă
24
+ este un document încorporat. Vă rugăm accesaţi colecţia din
25
+ documentul rădăcină.
26
+ invalid_field:
27
+ Folosirea denumirii %{name} ptr. un câmp este interzisă. Vă
28
+ rugăm să evitaţi utilizarea acelor cuvinte care intră în conflict
29
+ cu denumirile folosite de proprietăţile sau metodele Mongoid-lui.
30
+ Folosiţi comanda Document#instance_methods pentru a afla care
31
+ sunt acestea.
32
+ too_many_nested_attribute_records:
33
+ În cazul %{association} folosirea atributelor îmbricate este
34
+ limitat la %{limit} înregistrări.
35
+ embedded_in_must_have_inverse_of:
36
+ Folosirea opţiunii inverse_of este obligatorie în cazul
37
+ asociaţiilor de tip embedded_in.
38
+ dependent_only_references_one_or_many:
39
+ Opţiunea dependent => destroy|delete poate fi folosită doar în
40
+ cazul asociaţiilor de tip references_one sau references_many.
41
+ association_cant_have_inverse_of:
42
+ Folosire opţiunii inverse_of la acest tip de asociaţie este
43
+ interzisă. Aceasta poate fi folosită doar la asociaţiile de
44
+ tip embedded_in sau references_many as array.
45
+ calling_document_find_with_nil_is_invalid:
46
+ Folosirea metodei Document#find cu valoarea nil este invalidă.
47
+
@@ -0,0 +1,31 @@
1
+ en:
2
+ activemodel:
3
+ errors:
4
+ messages:
5
+ taken: 已占用
6
+
7
+ mongoid:
8
+ errors:
9
+ messages:
10
+ document_not_found:
11
+ 没有发现类是%{klass}id(s)是%{identifiers}的文档
12
+ invalid_database:
13
+ 数据库应该是Mongo::DB,而不是%{name}.
14
+ invalid_type:
15
+ 在类%{klass}中定义了字段,实际值是%{value}的%{other}.
16
+ unsupported_version:
17
+ MongoDB %{version} 版本已过期,请升级到 %{mongo_version}.
18
+ validations:
19
+ 校验失败 - %{errors}.
20
+ invalid_collection:
21
+ 不允许直接访问嵌入式的集合%{klass} , 请从文档的根访问集合.
22
+ invalid_field:
23
+ 字段的名字不允许为 %{name}. 你不应该定义跟Mongoid内部属性或者方法相同的名字,详细请看Use Document#instance_methods.
24
+ too_many_nested_attribute_records:
25
+ 被关联的%{association} 嵌入式属性不能超过 %{limit}.
26
+ embedded_in_must_have_inverse_of:
27
+ embedded_in的关联属性必须包含inverse_of.
28
+ dependent_only_references_one_or_many:
29
+ dependent => destroy|delete 选项只有在references_one或者references_many时候有效.
30
+ association_cant_have_inverse_of:
31
+ 在当前的关联中,不允许定义inverse_of去,其只有在embedded_in或者references_many是数组的情况下使用
@@ -70,6 +70,7 @@ require "mongoid/logger"
70
70
  require "mongoid/matchers"
71
71
  require "mongoid/memoization"
72
72
  require "mongoid/modifiers"
73
+ require "mongoid/multi_parameter_attributes"
73
74
  require "mongoid/named_scope"
74
75
  require "mongoid/paths"
75
76
  require "mongoid/persistence"
@@ -15,6 +15,7 @@ module Mongoid #:nodoc:
15
15
  :index_information,
16
16
  :map_reduce,
17
17
  :mapreduce,
18
+ :stats,
18
19
  :options
19
20
  ]
20
21
 
@@ -25,6 +25,7 @@ module Mongoid #:nodoc
25
25
  include Mongoid::Matchers
26
26
  include Mongoid::Memoization
27
27
  include Mongoid::Modifiers
28
+ include Mongoid::MultiParameterAttributes
28
29
  include Mongoid::Paths
29
30
  include Mongoid::Persistence
30
31
  include Mongoid::Safety
@@ -48,6 +48,35 @@ module Mongoid #:nodoc
48
48
  attr_reader :use_utc
49
49
  alias_method :use_utc?, :use_utc
50
50
 
51
+ # Sets whether the times returned from the database use the ruby or
52
+ # the ActiveSupport time zone.
53
+ # If you omit this setting, then times will use the ruby time zone.
54
+ #
55
+ # Example:
56
+ #
57
+ # <tt>Config.use_activesupport_time_zone = true</tt>
58
+ #
59
+ # Returns:
60
+ #
61
+ # A boolean
62
+ def use_activesupport_time_zone=(value)
63
+ @use_activesupport_time_zone = value || false
64
+ end
65
+
66
+ # Sets whether the times returned from the database use the ruby or
67
+ # the ActiveSupport time zone.
68
+ # If the setting is false, then times will use the ruby time zone.
69
+ #
70
+ # Example:
71
+ #
72
+ # <tt>Config.use_activesupport_time_zone</tt>
73
+ #
74
+ # Returns:
75
+ #
76
+ # A boolean
77
+ attr_reader :use_activesupport_time_zone
78
+ alias_method :use_activesupport_time_zone?, :use_activesupport_time_zone
79
+
51
80
  # Sets the Mongo::DB master database to be used. If the object trying to be
52
81
  # set is not a valid +Mongo::DB+, then an error will be raised.
53
82
  #
@@ -235,8 +235,14 @@ module Mongoid #:nodoc:
235
235
  unless @selector[key]
236
236
  @selector[key] = { operator => value }
237
237
  else
238
- new_value = @selector[key].values.first + value
239
- @selector[key] = { operator => new_value }
238
+ if @selector[key].has_key?(operator)
239
+ # add the value to the current operator
240
+ new_value = @selector[key].values.first + value
241
+ @selector[key] = { operator => new_value }
242
+ else
243
+ # create a new operator on this key
244
+ @selector[key][operator] = value
245
+ end
240
246
  end
241
247
  end; self
242
248
  end
@@ -91,7 +91,7 @@ module Mongoid #:nodoc:
91
91
  #
92
92
  # Options:
93
93
  #
94
- # object_id: A single id or an array of ids in +String+ or <tt>BSON::ObjectID</tt> format
94
+ # object_id: A single id or an array of ids in +String+ or <tt>BSON::ObjectId</tt> format
95
95
  #
96
96
  # Example:
97
97
  #
@@ -103,11 +103,11 @@ module Mongoid #:nodoc:
103
103
  ids.flatten!
104
104
  if ids.size > 1
105
105
  self.in(
106
- :_id => ::BSON::ObjectID.cast!(@klass, ids, @klass.primary_key.nil?)
106
+ :_id => ::BSON::ObjectId.cast!(@klass, ids, @klass.primary_key.nil?)
107
107
  )
108
108
  else
109
109
  @selector[:_id] =
110
- ::BSON::ObjectID.cast!(@klass, ids.first, @klass.primary_key.nil?)
110
+ ::BSON::ObjectId.cast!(@klass, ids.first, @klass.primary_key.nil?)
111
111
  end
112
112
  self
113
113
  end
@@ -100,9 +100,9 @@ module Mongoid #:nodoc:
100
100
  #
101
101
  # attrs: The attributes +Hash+ to set up the document with.
102
102
  def initialize(attrs = nil)
103
+ @new_record = true
103
104
  @attributes = default_attributes
104
105
  process(attrs)
105
- @new_record = true
106
106
  document = yield self if block_given?
107
107
  identify
108
108
  run_callbacks(:initialize) do
@@ -9,7 +9,9 @@ module Mongoid #:nodoc
9
9
  #
10
10
  # <tt>Validations.new(person.errors)</tt>
11
11
  class Validations < MongoidError
12
+ attr_reader :document
12
13
  def initialize(document)
14
+ @document = document
13
15
  super(
14
16
  translate(
15
17
  "validations",
@@ -26,7 +26,7 @@ require "mongoid/extensions/string/inflections"
26
26
  require "mongoid/extensions/symbol/inflections"
27
27
  require "mongoid/extensions/symbol/conversions"
28
28
  require "mongoid/extensions/true_class/equality"
29
- require "mongoid/extensions/objectid/conversions"
29
+ require "mongoid/extensions/object_id/conversions"
30
30
 
31
31
  class Array #:nodoc
32
32
  include Mongoid::Extensions::Array::Accessors
@@ -112,8 +112,8 @@ class TrueClass #:nodoc
112
112
  include Mongoid::Extensions::TrueClass::Equality
113
113
  end
114
114
 
115
- class BSON::ObjectID #:nodoc
116
- extend Mongoid::Extensions::ObjectID::Conversions
115
+ class BSON::ObjectId #:nodoc
116
+ extend Mongoid::Extensions::ObjectId::Conversions
117
117
 
118
118
  def as_json(options = nil)
119
119
  to_s
@@ -16,6 +16,7 @@ module Mongoid #:nodoc:
16
16
 
17
17
  def convert_to_time(value)
18
18
  value = ::Date.parse(value) if value.is_a?(::String)
19
+ value = ::Date.civil(*value) if value.is_a?(::Array)
19
20
  ::Time.utc(value.year, value.month, value.day)
20
21
  end
21
22
  end
@@ -1,12 +1,12 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Extensions #:nodoc:
4
- module ObjectID #:nodoc:
4
+ module ObjectId #:nodoc:
5
5
  module Conversions #:nodoc:
6
6
 
7
7
  def set(value)
8
8
  if value.is_a?(::String)
9
- BSON::ObjectID.from_string(value) unless value.blank?
9
+ BSON::ObjectId.from_string(value) unless value.blank?
10
10
  else
11
11
  value
12
12
  end
@@ -16,13 +16,13 @@ module Mongoid #:nodoc:
16
16
  value
17
17
  end
18
18
 
19
- # If the document is using BSON::ObjectIDs the convert the argument to
19
+ # If the document is using BSON::ObjectIds the convert the argument to
20
20
  # either an object id or an array of them if the supplied argument is an
21
21
  # Array. Otherwise just return.
22
22
  #
23
23
  # Options:
24
- # args: A +String+ or an +Array+ convert to +BSON::ObjectID+
25
- # cast: A +Boolean+ define if we can or not cast to BSON::ObjectID.
24
+ # args: A +String+ or an +Array+ convert to +BSON::ObjectId+
25
+ # cast: A +Boolean+ define if we can or not cast to BSON::ObjectId.
26
26
  # If false, we use the default type of args
27
27
  #
28
28
  # Example:
@@ -33,19 +33,19 @@ module Mongoid #:nodoc:
33
33
  # Returns:
34
34
  #
35
35
  # If using object ids:
36
- # An +Array+ of +BSON::ObjectID+ of each element if params is an +Array+
37
- # A +BSON::ObjectID+ from params if params is +String+
36
+ # An +Array+ of +BSON::ObjectId+ of each element if params is an +Array+
37
+ # A +BSON::ObjectId+ from params if params is +String+
38
38
  # Otherwise:
39
39
  # <tt>args</tt>
40
40
  def cast!(klass, args, cast = true)
41
- if !klass.using_object_ids? || args.is_a?(::BSON::ObjectID) || !cast
41
+ if !klass.using_object_ids? || args.is_a?(::BSON::ObjectId) || !cast
42
42
  return args
43
43
  end
44
44
  if args.is_a?(::String)
45
- ::BSON::ObjectID(args)
45
+ ::BSON::ObjectId(args)
46
46
  elsif args.is_a?(::Array)
47
47
  args.map{ |a|
48
- a.is_a?(::BSON::ObjectID) ? a : ::BSON::ObjectID(a)
48
+ a.is_a?(::BSON::ObjectId) ? a : ::BSON::ObjectId(a)
49
49
  }
50
50
  else
51
51
  args
@@ -9,11 +9,12 @@ module Mongoid #:nodoc:
9
9
 
10
10
  def get(value)
11
11
  return nil if value.blank?
12
- if Mongoid::Config.instance.use_utc?
13
- value
14
- else
15
- value.getlocal
12
+ value = value.getlocal unless Mongoid::Config.instance.use_utc?
13
+ if Mongoid::Config.instance.use_activesupport_time_zone?
14
+ time_zone = Mongoid::Config.instance.use_utc? ? 'UTC' : Time.zone
15
+ value = value.in_time_zone(time_zone)
16
16
  end
17
+ value
17
18
  end
18
19
 
19
20
  protected
@@ -23,13 +24,15 @@ module Mongoid #:nodoc:
23
24
  end
24
25
 
25
26
  def convert_to_time(value)
27
+ time = Mongoid::Config.instance.use_activesupport_time_zone? ? ::Time.zone : ::Time
26
28
  case value
27
- when ::String then ::Time.parse(value)
28
- when ::DateTime then ::Time.utc(value.year, value.month, value.day, value.hour, value.min, value.sec)
29
- when ::Date then ::Time.utc(value.year, value.month, value.day)
29
+ when ::String then time.parse(value)
30
+ when ::DateTime then time.local(value.year, value.month, value.day, value.hour, value.min, value.sec)
31
+ when ::Date then time.local(value.year, value.month, value.day)
32
+ when ::Array then time.local(*value)
30
33
  else value
31
34
  end
32
35
  end
33
36
  end
34
37
  end
35
- end
38
+ end
@@ -48,7 +48,7 @@ module Mongoid #:nodoc:
48
48
  type.set(object)
49
49
  else
50
50
  inverse = @options[:inverse_class_name].constantize
51
- object.blank? ? type.set(object) : BSON::ObjectID.cast!(inverse, object)
51
+ object.blank? ? type.set(object) : BSON::ObjectId.cast!(inverse, object)
52
52
  end
53
53
  end
54
54
 
@@ -63,7 +63,7 @@ module Mongoid #:nodoc:
63
63
  #
64
64
  # <tt>Person.find(Mongo::ObjectID.new.to_s)</tt>
65
65
  def find(*args)
66
- raise Errors::InvalidOptions.new("Calling Document#find with nil is invalid") if args[0].nil?
66
+ raise Errors::InvalidOptions.new(:calling_document_find_with_nil_is_invalid, {}) if args[0].nil?
67
67
  type = args.delete_at(0) if args[0].is_a?(Symbol)
68
68
  criteria = Criteria.translate(self, *args)
69
69
  case type
@@ -24,7 +24,7 @@ module Mongoid #:nodoc:
24
24
  protected
25
25
  # Return the proper id for the document.
26
26
  def generate_id
27
- id = BSON::ObjectID.new
27
+ id = BSON::ObjectId.new
28
28
  @document.using_object_ids? ? id : id.to_s
29
29
  end
30
30
 
@@ -4,7 +4,7 @@ module Mongoid #:nodoc:
4
4
  extend ActiveSupport::Concern
5
5
  included do
6
6
  cattr_accessor :primary_key, :_identity
7
- self._identity = { :type => BSON::ObjectID }
7
+ self._identity = { :type => BSON::ObjectId }
8
8
 
9
9
  delegate \
10
10
  :_id_type,
@@ -28,9 +28,9 @@ module Mongoid #:nodoc:
28
28
  end
29
29
 
30
30
  # Used for telling Mongoid on a per model basis whether to override the
31
- # default +BSON::ObjectID+ and use a different type. This will be
31
+ # default +BSON::ObjectId+ and use a different type. This will be
32
32
  # expanded in the future for requiring a PkFactory if the type is not a
33
- # +BSON::ObjectID+ or +String+.
33
+ # +BSON::ObjectId+ or +String+.
34
34
  #
35
35
  # Example:
36
36
  #
@@ -59,7 +59,7 @@ module Mongoid #:nodoc:
59
59
  set_callback :save, :before, :identify
60
60
  end
61
61
 
62
- # Convenience method for determining if we are using +BSON::ObjectIDs+ as
62
+ # Convenience method for determining if we are using +BSON::ObjectIds+ as
63
63
  # our id.
64
64
  #
65
65
  # Example:
@@ -68,9 +68,9 @@ module Mongoid #:nodoc:
68
68
  #
69
69
  # Returns:
70
70
  #
71
- # true if we are using BSON::ObjectIDs
71
+ # true if we are using BSON::ObjectIds
72
72
  def using_object_ids?
73
- _id_type == BSON::ObjectID
73
+ _id_type == BSON::ObjectId
74
74
  end
75
75
  end
76
76
  end
@@ -0,0 +1,80 @@
1
+ # encoding: utf-8
2
+ module Mongoid #:nodoc:
3
+ module MultiParameterAttributes
4
+ module Errors
5
+ # Raised when an error occurred while doing a mass assignment to an attribute through the
6
+ # <tt>attributes=</tt> method. The exception has an +attribute+ property that is the name of the
7
+ # offending attribute.
8
+ class AttributeAssignmentError < Mongoid::Errors::MongoidError
9
+ attr_reader :exception, :attribute
10
+ def initialize(message, exception, attribute)
11
+ @exception = exception
12
+ @attribute = attribute
13
+ @message = message
14
+ end
15
+ end
16
+
17
+ # Raised when there are multiple errors while doing a mass assignment through the +attributes+
18
+ # method. The exception has an +errors+ property that contains an array of AttributeAssignmentError
19
+ # objects, each corresponding to the error while assigning to an attribute.
20
+ class MultiparameterAssignmentErrors < Mongoid::Errors::MongoidError
21
+ attr_reader :errors
22
+ def initialize(errors)
23
+ @errors = errors
24
+ end
25
+ end
26
+ end
27
+
28
+ def process(attrs = nil)
29
+ if attrs
30
+ errors = []
31
+ attributes = {}
32
+ multi_parameter_attributes = {}
33
+
34
+ attrs.each_pair do |key, value|
35
+ if key =~ /^([^\(]+)\((\d+)([if])\)$/
36
+ key, index = $1, $2.to_i
37
+ (multi_parameter_attributes[key] ||= {})[index] = value.empty? ? nil : value.send("to_#{$3}")
38
+ else
39
+ attributes[key] = value
40
+ end
41
+ end
42
+
43
+ multi_parameter_attributes.each_pair do |key, values|
44
+ begin
45
+ values = (values.keys.min..values.keys.max).map { |i| values[i] }
46
+ klass = self.class.fields[key].try(:type)
47
+ attributes[key] = instantiate_object(klass, values)
48
+ rescue => e
49
+ errors << Errors::AttributeAssignmentError.new("error on assignment #{values.inspect} to #{key}", e, key)
50
+ end
51
+ end
52
+
53
+ unless errors.empty?
54
+ raise Errors::MultiparameterAssignmentErrors.new(errors), "#{errors.size} error(s) on assignment of multiparameter attributes"
55
+ end
56
+
57
+ super attributes
58
+ else
59
+ super
60
+ end
61
+ end
62
+
63
+ protected
64
+
65
+ def instantiate_object(klass, values_with_empty_parameters)
66
+ return nil if values_with_empty_parameters.all? { |v| v.nil? }
67
+
68
+ values = values_with_empty_parameters.collect { |v| v.nil? ? 1 : v }
69
+
70
+ if klass == DateTime || klass == Date || klass == Time
71
+ klass.send(:convert_to_time, values)
72
+ elsif klass
73
+ klass.new *values
74
+ else
75
+ values
76
+ end
77
+ end
78
+
79
+ end
80
+ end
@@ -84,7 +84,7 @@ namespace :db do
84
84
 
85
85
  def convert_ids(obj)
86
86
  if obj.is_a?(String) && obj =~ /^[a-f0-9]{24}$/
87
- BSON::ObjectID(obj)
87
+ BSON::ObjectId(obj)
88
88
  elsif obj.is_a?(Array)
89
89
  obj.map do |v|
90
90
  convert_ids(v)
@@ -24,9 +24,9 @@ module Mongoid #:nodoc:
24
24
  criteria = document._parent.send(document.association_name)
25
25
  # If the parent document embeds_one, no need to validate uniqueness
26
26
  return if criteria.is_a?(Mongoid::Document)
27
- criteria = criteria.where(attribute => value, :_id => {'$ne' => document._id})
27
+ criteria = criteria.where(attribute => unique_search_value(value), :_id => {'$ne' => document._id})
28
28
  else
29
- criteria = @klass.where(attribute => value)
29
+ criteria = @klass.where(attribute => unique_search_value(value))
30
30
  unless document.new_record?
31
31
  criteria = criteria.where(:_id => {'$ne' => document._id})
32
32
  end
@@ -50,6 +50,15 @@ module Mongoid #:nodoc:
50
50
  return true if document.send("#{key}_changed?")
51
51
  end; false
52
52
  end
53
+
54
+ # ensure :case_sensitive is true by default
55
+ def unique_search_value(value)
56
+ if options[:case_sensitive] == false
57
+ value ? /^#{value}$/i : nil
58
+ else
59
+ value
60
+ end
61
+ end
53
62
  end
54
63
  end
55
64
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc
3
- VERSION = "2.0.0.beta.18"
3
+ VERSION = "2.0.0.beta.19"
4
4
  end
@@ -16,7 +16,6 @@ test:
16
16
 
17
17
  # set these environment variables on your prod server
18
18
  production:
19
- <<: *defaults
20
19
  host: <%%= ENV['MONGOID_HOST'] %>
21
20
  port: <%%= ENV['MONGOID_PORT'] %>
22
21
  username: <%%= ENV['MONGOID_USERNAME'] %>
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 62196421
4
5
  prerelease: true
5
6
  segments:
6
7
  - 2
7
8
  - 0
8
9
  - 0
9
10
  - beta
10
- - 18
11
- version: 2.0.0.beta.18
11
+ - 19
12
+ version: 2.0.0.beta.19
12
13
  platform: ruby
13
14
  authors:
14
15
  - Durran Jordan
@@ -16,121 +17,111 @@ autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2010-09-14 00:00:00 -04:00
20
+ date: 2010-09-29 00:00:00 -07:00
20
21
  default_executable:
21
22
  dependencies:
22
23
  - !ruby/object:Gem::Dependency
23
- name: activemodel
24
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
+ hash: 7
29
30
  segments:
30
31
  - 3
31
32
  - 0
32
- - 0
33
- version: 3.0.0
33
+ version: "3.0"
34
+ requirement: *id001
34
35
  type: :runtime
36
+ name: activemodel
35
37
  prerelease: false
36
- version_requirements: *id001
37
38
  - !ruby/object:Gem::Dependency
38
- name: tzinfo
39
- requirement: &id002 !ruby/object:Gem::Requirement
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
43
43
  - !ruby/object:Gem::Version
44
+ hash: 63
44
45
  segments:
45
46
  - 0
46
47
  - 3
47
48
  - 22
48
49
  version: 0.3.22
50
+ requirement: *id002
49
51
  type: :runtime
52
+ name: tzinfo
50
53
  prerelease: false
51
- version_requirements: *id002
52
54
  - !ruby/object:Gem::Dependency
53
- name: will_paginate
54
- requirement: &id003 !ruby/object:Gem::Requirement
55
+ version_requirements: &id003 !ruby/object:Gem::Requirement
55
56
  none: false
56
57
  requirements:
57
58
  - - ~>
58
59
  - !ruby/object:Gem::Version
60
+ hash: 961915916
59
61
  segments:
60
62
  - 3
61
63
  - 0
62
64
  - pre
63
65
  version: 3.0.pre
66
+ requirement: *id003
64
67
  type: :runtime
68
+ name: will_paginate
65
69
  prerelease: false
66
- version_requirements: *id003
67
- - !ruby/object:Gem::Dependency
68
- name: mongo
69
- requirement: &id004 !ruby/object:Gem::Requirement
70
- none: false
71
- requirements:
72
- - - "="
73
- - !ruby/object:Gem::Version
74
- segments:
75
- - 1
76
- - 0
77
- - 7
78
- version: 1.0.7
79
- type: :runtime
80
- prerelease: false
81
- version_requirements: *id004
82
70
  - !ruby/object:Gem::Dependency
83
- name: bson
84
- requirement: &id005 !ruby/object:Gem::Requirement
71
+ version_requirements: &id004 !ruby/object:Gem::Requirement
85
72
  none: false
86
73
  requirements:
87
74
  - - "="
88
75
  - !ruby/object:Gem::Version
76
+ hash: 5
89
77
  segments:
90
78
  - 1
91
79
  - 0
92
- - 4
93
- version: 1.0.4
80
+ - 9
81
+ version: 1.0.9
82
+ requirement: *id004
94
83
  type: :runtime
84
+ name: mongo
95
85
  prerelease: false
96
- version_requirements: *id005
97
86
  - !ruby/object:Gem::Dependency
98
- name: bson_ext
99
- requirement: &id006 !ruby/object:Gem::Requirement
87
+ version_requirements: &id005 !ruby/object:Gem::Requirement
100
88
  none: false
101
89
  requirements:
102
90
  - - "="
103
91
  - !ruby/object:Gem::Version
92
+ hash: 5
104
93
  segments:
105
94
  - 1
106
95
  - 0
107
- - 4
108
- version: 1.0.4
96
+ - 9
97
+ version: 1.0.9
98
+ requirement: *id005
109
99
  type: :development
100
+ name: bson_ext
110
101
  prerelease: false
111
- version_requirements: *id006
112
102
  - !ruby/object:Gem::Dependency
113
- name: mocha
114
- requirement: &id007 !ruby/object:Gem::Requirement
103
+ version_requirements: &id006 !ruby/object:Gem::Requirement
115
104
  none: false
116
105
  requirements:
117
106
  - - "="
118
107
  - !ruby/object:Gem::Version
108
+ hash: 43
119
109
  segments:
120
110
  - 0
121
111
  - 9
122
112
  - 8
123
113
  version: 0.9.8
114
+ requirement: *id006
124
115
  type: :development
116
+ name: mocha
125
117
  prerelease: false
126
- version_requirements: *id007
127
118
  - !ruby/object:Gem::Dependency
128
- name: rspec
129
- requirement: &id008 !ruby/object:Gem::Requirement
119
+ version_requirements: &id007 !ruby/object:Gem::Requirement
130
120
  none: false
131
121
  requirements:
132
122
  - - "="
133
123
  - !ruby/object:Gem::Version
124
+ hash: 62196431
134
125
  segments:
135
126
  - 2
136
127
  - 0
@@ -138,38 +129,41 @@ dependencies:
138
129
  - beta
139
130
  - 22
140
131
  version: 2.0.0.beta.22
132
+ requirement: *id007
141
133
  type: :development
134
+ name: rspec
142
135
  prerelease: false
143
- version_requirements: *id008
144
136
  - !ruby/object:Gem::Dependency
145
- name: watchr
146
- requirement: &id009 !ruby/object:Gem::Requirement
137
+ version_requirements: &id008 !ruby/object:Gem::Requirement
147
138
  none: false
148
139
  requirements:
149
140
  - - "="
150
141
  - !ruby/object:Gem::Version
142
+ hash: 7
151
143
  segments:
152
144
  - 0
153
145
  - 6
154
146
  version: "0.6"
147
+ requirement: *id008
155
148
  type: :development
149
+ name: watchr
156
150
  prerelease: false
157
- version_requirements: *id009
158
151
  - !ruby/object:Gem::Dependency
159
- name: ruby-debug-wrapper
160
- requirement: &id010 !ruby/object:Gem::Requirement
152
+ version_requirements: &id009 !ruby/object:Gem::Requirement
161
153
  none: false
162
154
  requirements:
163
155
  - - "="
164
156
  - !ruby/object:Gem::Version
157
+ hash: 29
165
158
  segments:
166
159
  - 0
167
160
  - 0
168
161
  - 1
169
162
  version: 0.0.1
163
+ requirement: *id009
170
164
  type: :development
165
+ name: ruby-debug-wrapper
171
166
  prerelease: false
172
- version_requirements: *id010
173
167
  description: Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written in Ruby.
174
168
  email:
175
169
  - durran@gmail.com
@@ -180,15 +174,20 @@ extensions: []
180
174
  extra_rdoc_files: []
181
175
 
182
176
  files:
177
+ - lib/config/locales/bg.yml
178
+ - lib/config/locales/de.yml
183
179
  - lib/config/locales/en.yml
184
180
  - lib/config/locales/es.yml
185
181
  - lib/config/locales/fr.yml
182
+ - lib/config/locales/hu.yml
186
183
  - lib/config/locales/it.yml
187
184
  - lib/config/locales/kr.yml
188
185
  - lib/config/locales/pl.yml
189
186
  - lib/config/locales/pt-br.yml
190
187
  - lib/config/locales/pt.yml
188
+ - lib/config/locales/ro.yml
191
189
  - lib/config/locales/sv.yml
190
+ - lib/config/locales/zh-CN.yml
192
191
  - lib/mongoid/associations/embedded_in.rb
193
192
  - lib/mongoid/associations/embeds_many.rb
194
193
  - lib/mongoid/associations/embeds_one.rb
@@ -258,7 +257,7 @@ files:
258
257
  - lib/mongoid/extensions/integer/conversions.rb
259
258
  - lib/mongoid/extensions/nil/assimilation.rb
260
259
  - lib/mongoid/extensions/object/conversions.rb
261
- - lib/mongoid/extensions/objectid/conversions.rb
260
+ - lib/mongoid/extensions/object_id/conversions.rb
262
261
  - lib/mongoid/extensions/proc/scoping.rb
263
262
  - lib/mongoid/extensions/set/conversions.rb
264
263
  - lib/mongoid/extensions/string/conversions.rb
@@ -297,6 +296,7 @@ files:
297
296
  - lib/mongoid/modifiers/command.rb
298
297
  - lib/mongoid/modifiers/inc.rb
299
298
  - lib/mongoid/modifiers.rb
299
+ - lib/mongoid/multi_parameter_attributes.rb
300
300
  - lib/mongoid/named_scope.rb
301
301
  - lib/mongoid/paranoia.rb
302
302
  - lib/mongoid/paths.rb
@@ -344,7 +344,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
344
344
  requirements:
345
345
  - - ">="
346
346
  - !ruby/object:Gem::Version
347
- hash: -407375290619395717
347
+ hash: 3
348
348
  segments:
349
349
  - 0
350
350
  version: "0"
@@ -353,6 +353,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
353
353
  requirements:
354
354
  - - ">="
355
355
  - !ruby/object:Gem::Version
356
+ hash: 23
356
357
  segments:
357
358
  - 1
358
359
  - 3