mongoid 2.3.5 → 2.4.0

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.
Files changed (126) hide show
  1. data/CHANGELOG.md +34 -176
  2. data/LICENSE +1 -1
  3. data/lib/config/locales/bg.yml +6 -0
  4. data/lib/config/locales/de.yml +6 -0
  5. data/lib/config/locales/en-GB.yml +8 -0
  6. data/lib/config/locales/en.yml +8 -0
  7. data/lib/config/locales/es.yml +9 -3
  8. data/lib/config/locales/fr.yml +6 -0
  9. data/lib/config/locales/hi.yml +6 -0
  10. data/lib/config/locales/hu.yml +6 -0
  11. data/lib/config/locales/id.yml +6 -0
  12. data/lib/config/locales/it.yml +6 -0
  13. data/lib/config/locales/ja.yml +6 -0
  14. data/lib/config/locales/kr.yml +6 -0
  15. data/lib/config/locales/nl.yml +8 -0
  16. data/lib/config/locales/pl.yml +6 -0
  17. data/lib/config/locales/pt-BR.yml +6 -0
  18. data/lib/config/locales/pt.yml +8 -2
  19. data/lib/config/locales/ro.yml +6 -0
  20. data/lib/config/locales/ru.yml +6 -0
  21. data/lib/config/locales/sv.yml +6 -0
  22. data/lib/config/locales/vi.yml +14 -8
  23. data/lib/config/locales/zh-CN.yml +6 -0
  24. data/lib/mongoid/atomic.rb +62 -13
  25. data/lib/mongoid/atomic/modifiers.rb +33 -1
  26. data/lib/mongoid/attributes.rb +5 -19
  27. data/lib/mongoid/callbacks.rb +2 -1
  28. data/lib/mongoid/collection.rb +2 -2
  29. data/lib/mongoid/collections/retry.rb +18 -6
  30. data/lib/mongoid/components.rb +2 -0
  31. data/lib/mongoid/config.rb +8 -63
  32. data/lib/mongoid/config/environment.rb +41 -0
  33. data/lib/mongoid/config/options.rb +74 -0
  34. data/lib/mongoid/contexts/enumerable.rb +0 -24
  35. data/lib/mongoid/contexts/mongo.rb +33 -3
  36. data/lib/mongoid/copyable.rb +1 -1
  37. data/lib/mongoid/criteria.rb +4 -2
  38. data/lib/mongoid/criterion/inclusion.rb +1 -16
  39. data/lib/mongoid/criterion/optional.rb +37 -10
  40. data/lib/mongoid/criterion/scoping.rb +83 -0
  41. data/lib/mongoid/criterion/selector.rb +9 -6
  42. data/lib/mongoid/default_scope.rb +1 -1
  43. data/lib/mongoid/dirty.rb +163 -29
  44. data/lib/mongoid/document.rb +58 -7
  45. data/lib/mongoid/errors.rb +2 -0
  46. data/lib/mongoid/errors/no_environment.rb +19 -0
  47. data/lib/mongoid/errors/scope_overwrite.rb +21 -0
  48. data/lib/mongoid/extensions.rb +6 -0
  49. data/lib/mongoid/extensions/array/deep_copy.rb +25 -0
  50. data/lib/mongoid/extensions/hash/deep_copy.rb +25 -0
  51. data/lib/mongoid/extensions/hash/scoping.rb +1 -1
  52. data/lib/mongoid/extensions/object/deep_copy.rb +21 -0
  53. data/lib/mongoid/extensions/proc/scoping.rb +2 -2
  54. data/lib/mongoid/extensions/symbol/inflections.rb +1 -0
  55. data/lib/mongoid/fields.rb +171 -104
  56. data/lib/mongoid/fields/{serializable → internal}/array.rb +33 -1
  57. data/lib/mongoid/fields/{serializable → internal}/big_decimal.rb +16 -1
  58. data/lib/mongoid/fields/{serializable → internal}/bignum.rb +1 -1
  59. data/lib/mongoid/fields/{serializable → internal}/binary.rb +1 -1
  60. data/lib/mongoid/fields/{serializable → internal}/boolean.rb +16 -1
  61. data/lib/mongoid/fields/{serializable → internal}/date.rb +1 -1
  62. data/lib/mongoid/fields/{serializable → internal}/date_time.rb +1 -1
  63. data/lib/mongoid/fields/{serializable → internal}/fixnum.rb +1 -1
  64. data/lib/mongoid/fields/{serializable → internal}/float.rb +16 -1
  65. data/lib/mongoid/fields/internal/foreign_keys/array.rb +74 -0
  66. data/lib/mongoid/fields/{serializable → internal}/foreign_keys/object.rb +11 -2
  67. data/lib/mongoid/fields/{serializable → internal}/hash.rb +1 -1
  68. data/lib/mongoid/fields/{serializable → internal}/integer.rb +16 -1
  69. data/lib/mongoid/fields/{serializable → internal}/localized.rb +23 -2
  70. data/lib/mongoid/fields/{serializable → internal}/nil_class.rb +16 -1
  71. data/lib/mongoid/fields/{serializable → internal}/object.rb +1 -1
  72. data/lib/mongoid/fields/{serializable → internal}/object_id.rb +16 -1
  73. data/lib/mongoid/fields/{serializable → internal}/range.rb +21 -2
  74. data/lib/mongoid/fields/{serializable → internal}/set.rb +16 -1
  75. data/lib/mongoid/fields/{serializable → internal}/string.rb +16 -1
  76. data/lib/mongoid/fields/{serializable → internal}/symbol.rb +17 -1
  77. data/lib/mongoid/fields/{serializable → internal}/time.rb +1 -1
  78. data/lib/mongoid/fields/{serializable → internal}/time_with_zone.rb +1 -1
  79. data/lib/mongoid/fields/{serializable → internal}/timekeeping.rb +16 -1
  80. data/lib/mongoid/fields/mappings.rb +8 -3
  81. data/lib/mongoid/fields/serializable.rb +34 -3
  82. data/lib/mongoid/hierarchy.rb +14 -14
  83. data/lib/mongoid/identity_map.rb +3 -2
  84. data/lib/mongoid/logger.rb +1 -7
  85. data/lib/mongoid/named_scope.rb +16 -12
  86. data/lib/mongoid/observer.rb +5 -1
  87. data/lib/mongoid/paranoia.rb +1 -0
  88. data/lib/mongoid/persistence.rb +11 -4
  89. data/lib/mongoid/persistence/atomic.rb +4 -1
  90. data/lib/mongoid/persistence/atomic/add_to_set.rb +17 -1
  91. data/lib/mongoid/persistence/atomic/sets.rb +1 -1
  92. data/lib/mongoid/railties/database.rake +1 -1
  93. data/lib/mongoid/relations.rb +1 -3
  94. data/lib/mongoid/relations/auto_save.rb +1 -1
  95. data/lib/mongoid/relations/builders.rb +1 -1
  96. data/lib/mongoid/relations/builders/embedded/many.rb +2 -6
  97. data/lib/mongoid/relations/builders/nested_attributes/many.rb +1 -1
  98. data/lib/mongoid/relations/builders/nested_attributes/one.rb +1 -1
  99. data/lib/mongoid/relations/builders/referenced/many_to_many.rb +1 -1
  100. data/lib/mongoid/relations/cascading/delete.rb +1 -1
  101. data/lib/mongoid/relations/cyclic.rb +10 -6
  102. data/lib/mongoid/relations/embedded/atomic.rb +3 -3
  103. data/lib/mongoid/relations/embedded/many.rb +98 -20
  104. data/lib/mongoid/relations/macros.rb +2 -0
  105. data/lib/mongoid/relations/many.rb +13 -0
  106. data/lib/mongoid/relations/metadata.rb +3 -3
  107. data/lib/mongoid/relations/nested_builder.rb +4 -3
  108. data/lib/mongoid/relations/proxy.rb +0 -1
  109. data/lib/mongoid/relations/referenced/batch.rb +3 -2
  110. data/lib/mongoid/relations/referenced/in.rb +3 -3
  111. data/lib/mongoid/relations/referenced/many.rb +89 -10
  112. data/lib/mongoid/relations/referenced/many_to_many.rb +34 -43
  113. data/lib/mongoid/relations/referenced/one.rb +8 -4
  114. data/lib/mongoid/relations/synchronization.rb +22 -5
  115. data/lib/mongoid/threaded.rb +38 -276
  116. data/lib/mongoid/threaded/lifecycle.rb +18 -18
  117. data/lib/mongoid/timestamps/updated.rb +13 -3
  118. data/lib/mongoid/validations.rb +22 -1
  119. data/lib/mongoid/validations/presence.rb +40 -0
  120. data/lib/mongoid/validations/uniqueness.rb +14 -3
  121. data/lib/mongoid/version.rb +1 -1
  122. data/lib/mongoid/versioning.rb +6 -2
  123. data/lib/rails/mongoid.rb +7 -1
  124. metadata +64 -45
  125. data/lib/mongoid/fields/serializable/foreign_keys/array.rb +0 -42
  126. data/lib/mongoid/relations/embedded/sort.rb +0 -31
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Fields #:nodoc:
4
- module Serializable #:nodoc:
4
+ module Internal #:nodoc:
5
5
 
6
6
  # Defines the behaviour for set fields.
7
7
  class Set
@@ -22,6 +22,21 @@ module Mongoid #:nodoc:
22
22
  ::Set.new(object)
23
23
  end
24
24
 
25
+ # Special case to serialize the object.
26
+ #
27
+ # @example Convert to a selection.
28
+ # field.selection(object)
29
+ #
30
+ # @param [ Object ] The object to convert.
31
+ #
32
+ # @return [ Object ] The converted object.
33
+ #
34
+ # @since 2.4.0
35
+ def selection(object)
36
+ return object if object.is_a?(::Hash)
37
+ serialize(object)
38
+ end
39
+
25
40
  # Serialize the object from the type defined in the model to a MongoDB
26
41
  # compatible object to store.
27
42
  #
@@ -1,12 +1,27 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Fields #:nodoc:
4
- module Serializable #:nodoc:
4
+ module Internal #:nodoc:
5
5
 
6
6
  # Defines the behaviour for string fields.
7
7
  class String
8
8
  include Serializable
9
9
 
10
+ # Special case to serialize the object.
11
+ #
12
+ # @example Convert to a selection.
13
+ # field.selection(object)
14
+ #
15
+ # @param [ Object ] The object to convert.
16
+ #
17
+ # @return [ Object ] The converted object.
18
+ #
19
+ # @since 2.4.0
20
+ def selection(object)
21
+ return object if object.is_a?(::Hash)
22
+ serialize(object)
23
+ end
24
+
10
25
  # Serialize the object from the type defined in the model to a MongoDB
11
26
  # compatible object to store.
12
27
  #
@@ -1,12 +1,27 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Fields #:nodoc:
4
- module Serializable #:nodoc:
4
+ module Internal #:nodoc:
5
5
 
6
6
  # Defines the behaviour for symbol fields.
7
7
  class Symbol
8
8
  include Serializable
9
9
 
10
+ # Special case to serialize the object.
11
+ #
12
+ # @example Convert to a selection.
13
+ # field.selection(object)
14
+ #
15
+ # @param [ Object ] The object to convert.
16
+ #
17
+ # @return [ Object ] The converted object.
18
+ #
19
+ # @since 2.4.0
20
+ def selection(object)
21
+ return object if object.is_a?(::Hash)
22
+ serialize(object)
23
+ end
24
+
10
25
  # Serialize the object from the type defined in the model to a MongoDB
11
26
  # compatible object to store.
12
27
  #
@@ -21,6 +36,7 @@ module Mongoid #:nodoc:
21
36
  def serialize(object)
22
37
  object.blank? ? nil : object.to_sym
23
38
  end
39
+ alias :deserialize :serialize
24
40
  end
25
41
  end
26
42
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Fields #:nodoc:
4
- module Serializable #:nodoc:
4
+ module Internal #:nodoc:
5
5
  # Defines the behaviour for date fields.
6
6
  class Time
7
7
  include Serializable
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Fields #:nodoc:
4
- module Serializable #:nodoc:
4
+ module Internal #:nodoc:
5
5
  # Defines the behaviour for time with zone fields.
6
6
  class TimeWithZone
7
7
  include Serializable
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Fields #:nodoc:
4
- module Serializable #:nodoc:
4
+ module Internal #:nodoc:
5
5
 
6
6
  # This module contains shared behaviour for date conversions.
7
7
  module Timekeeping
@@ -38,6 +38,21 @@ module Mongoid #:nodoc:
38
38
  object
39
39
  end
40
40
 
41
+ # Special case to serialize the object.
42
+ #
43
+ # @example Convert to a selection.
44
+ # field.selection(object)
45
+ #
46
+ # @param [ Object ] The object to convert.
47
+ #
48
+ # @return [ Object ] The converted object.
49
+ #
50
+ # @since 2.4.0
51
+ def selection(object)
52
+ return object if object.is_a?(::Hash)
53
+ serialize(object)
54
+ end
55
+
41
56
  # Serialize the object from the type defined in the model to a MongoDB
42
57
  # compatible object to store.
43
58
  #
@@ -7,7 +7,7 @@ module Mongoid #:nodoc
7
7
  module Mappings
8
8
  extend self
9
9
 
10
- MODULE = "Mongoid::Fields::Serializable"
10
+ MODULE = "Mongoid::Fields::Internal"
11
11
 
12
12
  # Get the custom field type for the provided class used in the field
13
13
  # definition.
@@ -21,12 +21,17 @@ module Mongoid #:nodoc
21
21
  #
22
22
  # @since 2.1.0
23
23
  def for(klass, foreign_key = false)
24
- return Serializable::Object unless klass
24
+ return Internal::Object unless klass
25
25
  if foreign_key
26
26
  return "#{MODULE}::ForeignKeys::#{klass.to_s.demodulize}".constantize
27
27
  end
28
28
  begin
29
- "#{MODULE}::#{klass.to_s.demodulize}".constantize
29
+ modules = "#{ MODULE }::|BSON::|ActiveSupport::"
30
+ if match = klass.to_s.match(Regexp.new("^(#{ modules })?(\\w+)$"))
31
+ "#{MODULE}::#{ match[2] }".constantize
32
+ else
33
+ klass.to_s.constantize
34
+ end
30
35
  rescue NameError
31
36
  klass
32
37
  end
@@ -81,6 +81,18 @@ module Mongoid #:nodoc:
81
81
  end
82
82
  end
83
83
 
84
+ # Is this field a foreign key?
85
+ #
86
+ # @example Is the field a foreign key?
87
+ # field.foreign_key?
88
+ #
89
+ # @return [ true, false ] If the field is a foreign key.
90
+ #
91
+ # @since 2.4.0
92
+ def foreign_key?
93
+ !!options[:identity]
94
+ end
95
+
84
96
  # Is the field localized or not?
85
97
  #
86
98
  # @example Is the field localized?
@@ -117,6 +129,16 @@ module Mongoid #:nodoc:
117
129
  @object_id_field ||= (type == BSON::ObjectId)
118
130
  end
119
131
 
132
+ # Can the field vary in size, similar to arrays.
133
+ #
134
+ # @example Is the field varying in size?
135
+ # field.resizable?
136
+ #
137
+ # @return [ false ] false by default.
138
+ #
139
+ # @since 2.4.0
140
+ def resizable?; false; end
141
+
120
142
  # Serialize the object from the type defined in the model to a MongoDB
121
143
  # compatible object to store.
122
144
  #
@@ -130,6 +152,18 @@ module Mongoid #:nodoc:
130
152
  # @since 2.1.0
131
153
  def serialize(object); object; end
132
154
 
155
+ # Convert the provided object to a Mongoid criteria friendly value.
156
+ #
157
+ # @example Convert the field.
158
+ # field.selection(object)
159
+ #
160
+ # @param [ Object ] The object to convert.
161
+ #
162
+ # @return [ Object ] The converted object.
163
+ #
164
+ # @since 2.4.0
165
+ def selection(object); object; end
166
+
133
167
  # Get the type of this field - inferred from the class name.
134
168
  #
135
169
  # @example Get the type.
@@ -175,9 +209,6 @@ module Mongoid #:nodoc:
175
209
  field.label = options[:label]
176
210
  field.localize = options[:localize]
177
211
  field.default_val = options[:default]
178
- unless field.default_val
179
- field.default_val = {} if field.localized?
180
- end
181
212
  end
182
213
  end
183
214
 
@@ -7,19 +7,6 @@ module Mongoid #:nodoc
7
7
  attr_accessor :_parent
8
8
  end
9
9
 
10
- module ClassMethods #:nodoc:
11
-
12
- # Determines if the document is a subclass of another document.
13
- #
14
- # @example Check if the document is a subclass.
15
- # Square.hereditary?
16
- #
17
- # @return [ true, false ] True if hereditary, false if not.
18
- def hereditary?
19
- Mongoid::Document > superclass
20
- end
21
- end
22
-
23
10
  # Get all child +Documents+ to this +Document+, going n levels deep if
24
11
  # necessary. This is used when calling update persistence operations from
25
12
  # the root document, where changes in the entire tree need to be
@@ -37,7 +24,7 @@ module Mongoid #:nodoc
37
24
  relations.each_pair do |name, metadata|
38
25
  if metadata.embedded?
39
26
  child = send(name)
40
- child.to_a.each do |doc|
27
+ Array.wrap(child).each do |doc|
41
28
  children.push(doc)
42
29
  children.concat(doc._children) unless metadata.versioned?
43
30
  end if child
@@ -113,5 +100,18 @@ module Mongoid #:nodoc
113
100
  while (object._parent) do object = object._parent; end
114
101
  object || self
115
102
  end
103
+
104
+ module ClassMethods #:nodoc:
105
+
106
+ # Determines if the document is a subclass of another document.
107
+ #
108
+ # @example Check if the document is a subclass.
109
+ # Square.hereditary?
110
+ #
111
+ # @return [ true, false ] True if hereditary, false if not.
112
+ def hereditary?
113
+ Mongoid::Document > superclass
114
+ end
115
+ end
116
116
  end
117
117
  end
@@ -16,7 +16,7 @@ module Mongoid #:nodoc:
16
16
  #
17
17
  # @since 2.1.0
18
18
  def get(klass, identifier)
19
- return nil unless Mongoid.identity_map_enabled?
19
+ return nil unless Mongoid.identity_map_enabled? && klass
20
20
  documents_for(klass)[identifier]
21
21
  end
22
22
 
@@ -93,7 +93,8 @@ module Mongoid #:nodoc:
93
93
  #
94
94
  # @since 2.1.0
95
95
  def documents_for(klass)
96
- self[klass] ||= {}
96
+ return nil unless klass
97
+ self[klass.collection_name] ||= {}
97
98
  end
98
99
 
99
100
  class << self
@@ -4,13 +4,7 @@ module Mongoid #:nodoc:
4
4
  # The Mongoid logger which wraps some other ruby compliant logger class.
5
5
  class Logger
6
6
 
7
- delegate \
8
- :info,
9
- :debug,
10
- :error,
11
- :fatal,
12
- :level,
13
- :unknown, :to => :logger, :allow_nil => true
7
+ delegate :info, :debug, :error, :fatal, :unknown, :to => :logger, :allow_nil => true
14
8
 
15
9
  # Emit a warning log message.
16
10
  #
@@ -24,8 +24,8 @@ module Mongoid #:nodoc:
24
24
  #
25
25
  # @since 2.0.0
26
26
  def criteria(embedded = false, scoped = true)
27
- scope_stack.last || Criteria.new(self, embedded).tap do |crit|
28
- return crit.fuse(default_scoping) if default_scoping && scoped
27
+ (scope_stack.last || Criteria.new(self, embedded)).tap do |crit|
28
+ return crit.apply_default_scope if scoped
29
29
  end
30
30
  end
31
31
 
@@ -56,7 +56,7 @@ module Mongoid #:nodoc:
56
56
  (class << self; self; end).class_eval <<-EOT
57
57
  def #{name}(*args)
58
58
  scope = scopes[:#{name}]
59
- scope.extend(criteria.fuse(scope.conditions.scoped(*args)))
59
+ scope.extend(criteria.fuse(scope.conditions.as_conditions(*args)))
60
60
  end
61
61
  EOT
62
62
  end
@@ -73,7 +73,7 @@ module Mongoid #:nodoc:
73
73
  #
74
74
  # @since 2.0.0
75
75
  def scoped(embedded = false)
76
- criteria(embedded, true)
76
+ criteria(embedded).scoped
77
77
  end
78
78
 
79
79
  # Initializes and returns the current scope stack.
@@ -99,7 +99,7 @@ module Mongoid #:nodoc:
99
99
  #
100
100
  # @since 2.0.0
101
101
  def unscoped(embedded = false)
102
- criteria(embedded, false)
102
+ criteria(embedded).unscoped
103
103
  end
104
104
 
105
105
  # Pushes the provided criteria onto the scope stack, and removes it after the
@@ -125,19 +125,23 @@ module Mongoid #:nodoc:
125
125
 
126
126
  protected
127
127
 
128
- # Warns if overriding another scope or method.
128
+ # Warns or raises exception if overriding another scope or method.
129
129
  #
130
- # @example Warn if name exists.
130
+ # @example Warn or raise error if name exists.
131
131
  # Model.valid_scope_name?("test")
132
132
  #
133
133
  # @param [ String, Symbol ] name The name of the scope.
134
134
  def valid_scope_name?(name)
135
135
  if scopes[name] || respond_to?(name, true)
136
- if Mongoid.logger
137
- Mongoid.logger.warn(
138
- "Creating scope :#{name}. " +
139
- "Overwriting existing method #{self.name}.#{name}."
140
- )
136
+ if Mongoid.scope_overwrite_exception
137
+ raise Errors::ScopeOverwrite.new(self.name,name)
138
+ else
139
+ if Mongoid.logger
140
+ Mongoid.logger.warn(
141
+ "Creating scope :#{name}. " +
142
+ "Overwriting existing method #{self.name}.#{name}."
143
+ )
144
+ end
141
145
  end
142
146
  end
143
147
  end
@@ -159,7 +159,11 @@ module Mongoid #:nodoc:
159
159
  callback_meth = :"_notify_#{observer_name}_for_#{callback}"
160
160
  unless klass.respond_to?(callback_meth)
161
161
  klass.send(:define_method, callback_meth) do |&block|
162
- observer.send(callback, self, &block)
162
+ if value = observer.update(callback, self, &block)
163
+ value
164
+ else
165
+ block.call if block
166
+ end
163
167
  end
164
168
  klass.send(callback, callback_meth)
165
169
  end
@@ -15,6 +15,7 @@ module Mongoid #:nodoc:
15
15
 
16
16
  included do
17
17
  field :deleted_at, :type => Time
18
+ self.paranoid = true
18
19
  end
19
20
 
20
21
  # Delete the paranoid +Document+ from the database completely. This will
@@ -28,7 +28,12 @@ module Mongoid #:nodoc:
28
28
  #
29
29
  # @return [ true, false ] True if successful, false if not.
30
30
  def destroy(options = {})
31
- run_callbacks(:destroy) { remove(options) }
31
+ self.flagged_for_destroy = true
32
+ run_callbacks(:destroy) do
33
+ remove(options)
34
+ end.tap do
35
+ self.flagged_for_destroy = false
36
+ end
32
37
  end
33
38
 
34
39
  # Insert a new document into the database. Will return the document
@@ -209,7 +214,8 @@ module Mongoid #:nodoc:
209
214
  #
210
215
  # @return [ Integer ] The number of documents deleted.
211
216
  def delete_all(conditions = nil)
212
- selector = (conditions || {})[:conditions] || {}
217
+ conds = conditions || {}
218
+ selector = conds[:conditions] || conds
213
219
  selector.merge!(:_type => name) if hereditary?
214
220
  collection.find(selector).count.tap do
215
221
  collection.remove(selector, Safety.merge_safety_options)
@@ -230,8 +236,9 @@ module Mongoid #:nodoc:
230
236
  # @param [ Hash ] conditions Optional conditions to destroy by.
231
237
  #
232
238
  # @return [ Integer ] The number of documents destroyed.
233
- def destroy_all(conditions = {})
234
- documents = all(conditions)
239
+ def destroy_all(conditions = nil)
240
+ conds = conditions || {}
241
+ documents = where(conds[:conditions] || conds)
235
242
  documents.count.tap do
236
243
  documents.each { |doc| doc.destroy }
237
244
  end