mongoid 3.1.2 → 3.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6a93ef3b8e16abfb336265ee706bf8dc3ca62f89
4
+ data.tar.gz: 8d27fd207900247df10d6c3e49b7eebf088b97b6
5
+ SHA512:
6
+ metadata.gz: f3ee03829a223c53df67171aec6ef170937e59f299e8f21e5cbc66ea10064455c4443addeb64e0c5b713acc8cec4421213f7e949c86f832aa60ff4c87620b015
7
+ data.tar.gz: 1e3825ba1089fe531844c0662c2137a66a050f31e4c1f52795c545ecc860ad205e96d5dba70795375f4274428bc5b9c5c48ae1ecbf8be34251c4642f87e6d087
@@ -3,6 +3,50 @@
3
3
  For instructions on upgrading to newer versions, visit
4
4
  [mongoid.org](http://mongoid.org/en/mongoid/docs/upgrading.html).
5
5
 
6
+ ## 3.1.4
7
+
8
+ ### Resolved Issues
9
+
10
+ * \#2944 Fixed uniqueness validation for localized fields when case insensitive
11
+ is true. (Vladimir Zhukov)
12
+
13
+ ## 3.1.3
14
+
15
+ ### Resolved Issues
16
+
17
+ * Dont duplicate embedded documents when saving after calling becomes method.
18
+
19
+ * \#2961 Reloading a mongoid.yml configuration now properly clears previously
20
+ configured sessions.
21
+
22
+ * \#2937 Counts can now take a `true` argument to factor in skip and limit.
23
+ (Arthur Neves)
24
+
25
+ * \#2921 Don't use type in identity map selection if inheritance is not
26
+ in play. (Arthur Neves)
27
+
28
+ * \#2899 Dirty attribute methods now properly handle field aliases.
29
+ (Niels Ganser)
30
+
31
+ * \#2895 Allow scopes that return nil to still be chainable. (niedhui)
32
+
33
+ * \#2893 Removed memoization of collection name and database name so lambdas
34
+ with `store_in` work properly when changing.
35
+
36
+ * \#2911 The `_destroy` attribute on 1-n relations when processing nested
37
+ attributes can now be a string or symbol when passed an array.
38
+
39
+ * \#2886 Fixed namespacing issue with Rails generators.
40
+
41
+ * \#2885 Fixed touch for aliased fields. (Niels Ganser)
42
+
43
+ * \#2883 Allow cyclic relations to not raise mixed relation errors.
44
+
45
+ * \#2867 `pluck` now properly handles aliased fields.
46
+
47
+ * \#2862 Autosaving no longer performs extra unnecessary queries.
48
+ (Arthur Neves)
49
+
6
50
  ## 3.1.2
7
51
 
8
52
  ### Resolved Issues
@@ -289,6 +333,13 @@ For instructions on upgrading to newer versions, visit
289
333
  * \#2664 In memory sorting of embedded documents now properly works when
290
334
  multiple fields are provided. (Neer Friedman)
291
335
 
336
+ ## 3.0.24
337
+
338
+ ### Resolved Issues
339
+
340
+ * \#2879 `remove_attribute` on new documents no longer creates an unnecessary
341
+ $unset operation.
342
+
292
343
  ## 3.0.23
293
344
 
294
345
  ### Resolved Issues
@@ -136,7 +136,7 @@ module Mongoid
136
136
  end
137
137
  _assigning do
138
138
  attribute_will_change!(access)
139
- delayed_atomic_unsets[atomic_attribute_name(access)] = []
139
+ delayed_atomic_unsets[atomic_attribute_name(access)] = [] unless new_record?
140
140
  attributes.delete(access)
141
141
  end
142
142
  end
@@ -87,7 +87,11 @@ module Mongoid
87
87
  # @since 2.0.1
88
88
  def load!(path, environment = nil)
89
89
  settings = Environment.load_yaml(path, environment)
90
- load_configuration(settings) if settings.present?
90
+ if settings.present?
91
+ Sessions.disconnect
92
+ Sessions.clear
93
+ load_configuration(settings)
94
+ end
91
95
  settings
92
96
  end
93
97
 
@@ -44,15 +44,19 @@ module Mongoid
44
44
  # doc.likes > 1
45
45
  # end
46
46
  #
47
- # @param [ Document ] document A document ot match.
47
+ # @param [ Document ] document A document to match or true if wanting
48
+ # skip and limit to be factored into the count.
48
49
  #
49
50
  # @return [ Integer ] The number of matches.
50
51
  #
51
52
  # @since 3.0.0
52
- def count(document = nil, &block)
53
+ def count(document = false, &block)
53
54
  return super(&block) if block_given?
54
- return (cached? ? @count ||= query.count : query.count) unless document
55
- collection.find(criteria.and(_id: document.id).selector).count
55
+ if document.is_a?(Document)
56
+ return collection.find(criteria.and(_id: document.id).selector).count
57
+ end
58
+ return query.count(document) if document
59
+ cached? ? @count ||= query.count : query.count
56
60
  end
57
61
 
58
62
  # Delete all documents in the database that match the selector.
@@ -332,7 +336,7 @@ module Mongoid
332
336
  #
333
337
  # @since 3.1.0
334
338
  def pluck(field)
335
- normalized = field.to_s
339
+ normalized = klass.database_field_name(field)
336
340
  query.select(normalized => 1).map{ |doc| doc[normalized] }.compact
337
341
  end
338
342
 
@@ -166,6 +166,7 @@ module Mongoid
166
166
  #
167
167
  # @since 2.1.0
168
168
  def attribute_change(attr)
169
+ attr = database_field_name(attr)
169
170
  [changed_attributes[attr], attributes[attr]] if attribute_changed?(attr)
170
171
  end
171
172
 
@@ -180,6 +181,7 @@ module Mongoid
180
181
  #
181
182
  # @since 2.1.6
182
183
  def attribute_changed?(attr)
184
+ attr = database_field_name(attr)
183
185
  return false unless changed_attributes.has_key?(attr)
184
186
  changed_attributes[attr] != attributes[attr]
185
187
  end
@@ -209,6 +211,7 @@ module Mongoid
209
211
  #
210
212
  # @since 2.4.0
211
213
  def attribute_was(attr)
214
+ attr = database_field_name(attr)
212
215
  attribute_changed?(attr) ? changed_attributes[attr] : attributes[attr]
213
216
  end
214
217
 
@@ -239,6 +242,7 @@ module Mongoid
239
242
  #
240
243
  # @since 2.4.0
241
244
  def reset_attribute!(attr)
245
+ attr = database_field_name(attr)
242
246
  attributes[attr] = changed_attributes.delete(attr) if attribute_changed?(attr)
243
247
  end
244
248
 
@@ -190,6 +190,17 @@ module Mongoid
190
190
  became.instance_variable_set(:@destroyed, destroyed?)
191
191
  became.changed_attributes["_type"] = self.class.to_s
192
192
  became._type = klass.to_s
193
+
194
+ # mark embedded docs as persisted
195
+ embedded_relations.each_pair do |name, meta|
196
+ without_autobuild do
197
+ relation = became.__send__(name)
198
+ Array.wrap(relation).each do |r|
199
+ r.instance_variable_set(:@new_record, new_record?)
200
+ end
201
+ end
202
+ end
203
+
193
204
  IdentityMap.set(became) unless became.new_record?
194
205
  became
195
206
  end
@@ -218,6 +218,7 @@ module Mongoid
218
218
  #
219
219
  # @since 3.0.7
220
220
  def database_field_name(name)
221
+ return nil unless name
221
222
  normalized = name.to_s
222
223
  aliased_fields[normalized] || normalized
223
224
  end
@@ -120,6 +120,7 @@ module Mongoid
120
120
  def touch(field = nil)
121
121
  return false if _root.new_record?
122
122
  current = Time.now
123
+ field = database_field_name(field)
123
124
  write_attribute(:updated_at, current) if respond_to?("updated_at=")
124
125
  write_attribute(field, current) if field
125
126
 
@@ -27,21 +27,32 @@ module Mongoid
27
27
  # Begin the associated autosave.
28
28
  #
29
29
  # @example Begin autosave.
30
- # document.begin_autosave
30
+ # document.__autosaving__
31
31
  #
32
- # @since 3.0.0
33
- def begin_autosave
32
+ # @since 3.1.3
33
+ def __autosaving__
34
34
  Threaded.begin_autosave(self)
35
+ yield
36
+ ensure
37
+ Threaded.exit_autosave(self)
35
38
  end
36
39
 
37
- # Exit the associated autosave.
40
+ # Check if there is changes for auto-saving
38
41
  #
39
- # @example Exit autosave.
40
- # document.exit_autosave
42
+ # @example Return true if there is changes on self or in
43
+ # autosaved relations.
44
+ # document.changed_for_autosave?
41
45
  #
42
- # @since 3.0.0
43
- def exit_autosave
44
- Threaded.exit_autosave(self)
46
+ # @since 3.1.3
47
+ def changed_for_autosave?
48
+ new_record? || changed? || marked_for_destruction?
49
+ end
50
+
51
+ # Returns the relation, if it exists
52
+ #
53
+ # @since 3.1.3
54
+ def relation_changed_for_autosave(metadata)
55
+ ivar(metadata.name) if self.class.autosaved_relations.include?(metadata.name)
45
56
  end
46
57
 
47
58
  module ClassMethods
@@ -64,14 +75,14 @@ module Mongoid
64
75
  if before_callback_halted?
65
76
  self.before_callback_halted = false
66
77
  else
67
- begin_autosave
68
- relation = document.send(metadata.name)
69
- if relation
70
- (relation.do_or_do_not(:in_memory) || Array.wrap(relation)).each do |doc|
71
- doc.save
78
+ __autosaving__ do
79
+ if document.changed_for_autosave? || relation = document.relation_changed_for_autosave(metadata)
80
+ relation = document.__send__(metadata.name) unless relation
81
+ (relation.do_or_do_not(:in_memory) || Array.wrap(relation)).each do |doc|
82
+ doc.save
83
+ end if relation
72
84
  end
73
85
  end
74
- exit_autosave
75
86
  end
76
87
  end
77
88
  end
@@ -26,9 +26,9 @@ module Mongoid
26
26
  end
27
27
  attributes.each do |attrs|
28
28
  if attrs.respond_to?(:with_indifferent_access)
29
- process_attributes(parent, attrs, options)
29
+ process_attributes(parent, attrs.with_indifferent_access, options)
30
30
  else
31
- process_attributes(parent, attrs[1], options)
31
+ process_attributes(parent, attrs[1].with_indifferent_access, options)
32
32
  end
33
33
  end
34
34
  end
@@ -18,7 +18,7 @@ module Mongoid
18
18
  return object unless query?
19
19
  return [] if object.is_a?(Array)
20
20
  crit = metadata.criteria(Conversions.flag(object, metadata), base.class)
21
- IdentityMap.get_many(crit.klass, crit.selector) || crit
21
+ IdentityMap.get_many(crit.klass, crit.send(:selector_with_type_selection)) || crit
22
22
  end
23
23
  end
24
24
  end
@@ -169,7 +169,7 @@ module Mongoid
169
169
  # Get the criteria that is used to query for this metadata's relation.
170
170
  #
171
171
  # @example Get the criteria.
172
- # metadata.criteria([ id_one, id_two ])
172
+ # metadata.criteria([ id_one, id_two ], Person)
173
173
  #
174
174
  # @param [ Object ] object The foreign key used for the query.
175
175
  # @param [ Class ] type The base class.
@@ -247,11 +247,15 @@ module Mongoid
247
247
  klass, foreign_key = metadata.klass, metadata.foreign_key
248
248
  eager_loaded = klass.any_in(foreign_key => ids).entries
249
249
  ids.each do |id|
250
- IdentityMap.clear_many(klass, metadata.type_relation.merge!(foreign_key => id))
250
+ sel = { foreign_key => id }
251
+ sel.merge!(metadata.type_relation) if klass.hereditary?
252
+ IdentityMap.clear_many(klass, sel)
251
253
  end
252
254
  eager_loaded.each do |doc|
253
255
  base_id = doc.__send__(foreign_key)
254
- yield(doc, metadata.type_relation.merge!(foreign_key => base_id))
256
+ sel = { foreign_key => base_id }
257
+ sel.merge!(metadata.type_relation) if klass.hereditary?
258
+ yield(doc, sel)
255
259
  end
256
260
  end
257
261
  end
@@ -218,7 +218,7 @@ module Mongoid
218
218
  # @since 2.0.0.beta.1
219
219
  def initialize(base, target, metadata)
220
220
  init(base, Targets::Enumerable.new(target), metadata) do
221
- raise_mixed if klass.embedded?
221
+ raise_mixed if klass.embedded? && !klass.cyclic?
222
222
  end
223
223
  end
224
224
 
@@ -18,7 +18,7 @@ module Mongoid
18
18
  # @param [ Metadata ] metadata The relation's metadata.
19
19
  def initialize(base, target, metadata)
20
20
  init(base, target, metadata) do
21
- raise_mixed if klass.embedded?
21
+ raise_mixed if klass.embedded? && !klass.cyclic?
22
22
  characterize_one(target)
23
23
  bind_one
24
24
  target.save if persistable?
@@ -277,7 +277,7 @@ module Mongoid
277
277
  def #{name}(*args)
278
278
  scoping = scopes[:#{name}]
279
279
  scope, extension = scoping[:scope][*args], scoping[:extension]
280
- criteria = with_default_scope.merge(scope)
280
+ criteria = with_default_scope.merge(scope || all)
281
281
  criteria.extend(extension)
282
282
  criteria
283
283
  end
@@ -183,7 +183,7 @@ module Mongoid
183
183
  #
184
184
  # @since 3.0.0
185
185
  def collection_name
186
- @collection_name ||= __collection_name__
186
+ __collection_name__
187
187
  end
188
188
 
189
189
  # Get the default database name for this model.
@@ -195,7 +195,7 @@ module Mongoid
195
195
  #
196
196
  # @since 3.0.0
197
197
  def database_name
198
- @database_name ||= __database_name__
198
+ __database_name__
199
199
  end
200
200
 
201
201
  # Get the overridden database name. This either can be overridden by
@@ -292,9 +292,8 @@ module Mongoid
292
292
  # @since 3.0.0
293
293
  def store_in(options)
294
294
  Validators::Storage.validate(self, options)
295
- @collection_name, @database_name = nil, nil
296
295
  self.storage_options ||= {}
297
- self.storage_options.merge! options
296
+ self.storage_options.merge!(options)
298
297
  end
299
298
 
300
299
  # Tell the next persistance operation to store in a specific collection,
@@ -104,13 +104,8 @@ module Mongoid
104
104
  #
105
105
  # @since 2.4.10
106
106
  def create_criteria(base, document, attribute, value)
107
- field = document.fields[attribute.to_s]
108
107
  criteria = scope(base.unscoped, document, attribute)
109
- if field.try(:localized?)
110
- criteria.selector.update(criterion(document, attribute, value))
111
- else
112
- criteria = criteria.where(criterion(document, attribute, value))
113
- end
108
+ criteria.selector.update(criterion(document, attribute, value))
114
109
  criteria
115
110
  end
116
111
 
@@ -129,7 +124,13 @@ module Mongoid
129
124
  #
130
125
  # @since 2.3.0
131
126
  def criterion(document, attribute, value)
132
- selector = { attribute => filter(value) }
127
+ if localized?(document, attribute)
128
+ conditions = value.inject([]) { |acc, (k,v)| acc << { "#{attribute}.#{k}" => filter(v) } }
129
+ selector = { "$or" => conditions }
130
+ else
131
+ selector = { attribute => filter(value) }
132
+ end
133
+
133
134
  if document.persisted? && !document.embedded?
134
135
  selector.merge!(_id: { "$ne" => document.id })
135
136
  end
@@ -305,6 +306,23 @@ module Mongoid
305
306
  def persistence_options(criteria)
306
307
  (criteria.klass.persistence_options || {}).merge!(consistency: :strong)
307
308
  end
309
+
310
+ # Is the attribute localized?
311
+ #
312
+ # @api private
313
+ #
314
+ # @example Is the attribute localized?
315
+ # validator.localized?(doc, :field)
316
+ #
317
+ # @param [ Document ] document The document getting validated.
318
+ # @param [ Symbol ] attribute The attribute to validate.
319
+ #
320
+ # @return [ true, false ] If the attribute is localized.
321
+ #
322
+ # @since 4.0.0
323
+ def localized?(document, attribute)
324
+ document.fields[attribute.to_s].try(:localized?)
325
+ end
308
326
  end
309
327
  end
310
328
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid
3
- VERSION = "3.1.2"
3
+ VERSION = "3.1.3"
4
4
  end
@@ -10,15 +10,6 @@ module Mongoid
10
10
  @_mongoid_source_root ||=
11
11
  File.expand_path("../#{base_name}/#{generator_name}/templates", __FILE__)
12
12
  end
13
-
14
- unless methods.include?(:module_namespacing)
15
-
16
- # This is only defined on Rails edge at the moment, so include here now
17
- # as per: https://github.com/mongoid/mongoid/issues/744
18
- def module_namespacing(&block)
19
- yield if block
20
- end
21
- end
22
13
  end
23
14
 
24
15
  class ActiveModel < ::Rails::Generators::ActiveModel
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.2
5
- prerelease:
4
+ version: 3.1.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Durran Jordan
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-24 00:00:00.000000000 Z
11
+ date: 2013-04-17 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activemodel
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: tzinfo
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: moped
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: origin
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -357,26 +348,25 @@ files:
357
348
  homepage: http://mongoid.org
358
349
  licenses:
359
350
  - MIT
351
+ metadata: {}
360
352
  post_install_message:
361
353
  rdoc_options: []
362
354
  require_paths:
363
355
  - lib
364
356
  required_ruby_version: !ruby/object:Gem::Requirement
365
- none: false
366
357
  requirements:
367
- - - ! '>='
358
+ - - '>='
368
359
  - !ruby/object:Gem::Version
369
360
  version: '1.9'
370
361
  required_rubygems_version: !ruby/object:Gem::Requirement
371
- none: false
372
362
  requirements:
373
- - - ! '>='
363
+ - - '>='
374
364
  - !ruby/object:Gem::Version
375
365
  version: 1.3.6
376
366
  requirements: []
377
367
  rubyforge_project: mongoid
378
- rubygems_version: 1.8.25
368
+ rubygems_version: 2.0.3
379
369
  signing_key:
380
- specification_version: 3
370
+ specification_version: 4
381
371
  summary: Elegant Persistance in Ruby for MongoDB.
382
372
  test_files: []