mongoid 2.3.0 → 2.3.1

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 (56) hide show
  1. data/CHANGELOG.md +56 -2
  2. data/lib/config/locales/bg.yml +2 -0
  3. data/lib/config/locales/de.yml +2 -0
  4. data/lib/config/locales/en-GB.yml +2 -0
  5. data/lib/config/locales/en.yml +2 -0
  6. data/lib/config/locales/es.yml +2 -0
  7. data/lib/config/locales/fr.yml +2 -0
  8. data/lib/config/locales/hi.yml +2 -0
  9. data/lib/config/locales/hu.yml +2 -0
  10. data/lib/config/locales/id.yml +2 -0
  11. data/lib/config/locales/it.yml +2 -0
  12. data/lib/config/locales/ja.yml +2 -0
  13. data/lib/config/locales/kr.yml +2 -0
  14. data/lib/config/locales/nl.yml +2 -0
  15. data/lib/config/locales/pl.yml +2 -0
  16. data/lib/config/locales/pt-BR.yml +2 -0
  17. data/lib/config/locales/pt.yml +2 -0
  18. data/lib/config/locales/ro.yml +2 -0
  19. data/lib/config/locales/ru.yml +2 -0
  20. data/lib/config/locales/sv.yml +2 -0
  21. data/lib/config/locales/vi.yml +2 -0
  22. data/lib/config/locales/zh-CN.yml +2 -0
  23. data/lib/mongoid/contexts/mongo.rb +1 -1
  24. data/lib/mongoid/criterion/inclusion.rb +39 -40
  25. data/lib/mongoid/criterion/selector.rb +5 -0
  26. data/lib/mongoid/dirty.rb +4 -26
  27. data/lib/mongoid/errors.rb +1 -0
  28. data/lib/mongoid/errors/invalid_time.rb +25 -0
  29. data/lib/mongoid/extensions.rb +2 -0
  30. data/lib/mongoid/extensions/hash/criteria_helpers.rb +1 -2
  31. data/lib/mongoid/extensions/object_id/conversions.rb +2 -4
  32. data/lib/mongoid/extensions/string/checks.rb +12 -0
  33. data/lib/mongoid/extensions/symbol/checks.rb +23 -0
  34. data/lib/mongoid/extras.rb +0 -22
  35. data/lib/mongoid/fields.rb +1 -1
  36. data/lib/mongoid/fields/serializable.rb +14 -7
  37. data/lib/mongoid/fields/serializable/timekeeping.rb +6 -2
  38. data/lib/mongoid/named_scope.rb +7 -3
  39. data/lib/mongoid/nested_attributes.rb +0 -12
  40. data/lib/mongoid/paranoia.rb +62 -8
  41. data/lib/mongoid/railties/database.rake +6 -3
  42. data/lib/mongoid/relations.rb +15 -0
  43. data/lib/mongoid/relations/bindings/referenced/in.rb +1 -1
  44. data/lib/mongoid/relations/builders/referenced/in.rb +1 -1
  45. data/lib/mongoid/relations/builders/referenced/one.rb +1 -2
  46. data/lib/mongoid/relations/cascading.rb +0 -12
  47. data/lib/mongoid/relations/embedded/many.rb +28 -9
  48. data/lib/mongoid/relations/macros.rb +8 -18
  49. data/lib/mongoid/relations/metadata.rb +2 -5
  50. data/lib/mongoid/relations/polymorphic.rb +0 -25
  51. data/lib/mongoid/relations/referenced/many.rb +29 -10
  52. data/lib/mongoid/relations/referenced/many_to_many.rb +13 -3
  53. data/lib/mongoid/relations/targets/enumerable.rb +2 -3
  54. data/lib/mongoid/version.rb +1 -1
  55. data/lib/mongoid/versioning.rb +1 -13
  56. metadata +21 -19
@@ -17,7 +17,7 @@ module Mongoid # :nodoc:
17
17
  def build(type = nil)
18
18
  return object unless query?
19
19
  model = type ? type.constantize : metadata.klass
20
- IdentityMap.get(model, object) || metadata.criteria(object, model).first
20
+ metadata.criteria(object, model).from_map_or_db
21
21
  end
22
22
  end
23
23
  end
@@ -16,8 +16,7 @@ module Mongoid # :nodoc:
16
16
  # @return [ Document ] A single document.
17
17
  def build(type = nil)
18
18
  return object unless query?
19
- criteria = metadata.criteria(Conversions.flag(object, metadata))
20
- IdentityMap.get(criteria.klass, criteria.selector) || criteria.first
19
+ metadata.criteria(Conversions.flag(object, metadata)).from_map_or_db
21
20
  end
22
21
  end
23
22
  end
@@ -34,18 +34,6 @@ module Mongoid # :nodoc:
34
34
  end
35
35
  end
36
36
 
37
- # Get the cascading definitions.
38
- #
39
- # @note Refactored from using delegate for class load performance.
40
- #
41
- # @example Get the cascades.
42
- # model.cascades
43
- #
44
- # @return [ Array<String> ] The cascading relation names.
45
- def cascades
46
- self.class.cascades
47
- end
48
-
49
37
  module ClassMethods #:nodoc:
50
38
 
51
39
  # Attempt to add the cascading information for the document to know how
@@ -39,12 +39,21 @@ module Mongoid # :nodoc:
39
39
  # @example Build a new document on the relation.
40
40
  # person.people.build(:name => "Bozo")
41
41
  #
42
- # @param [ Hash ] attributes The attributes to build the document with.
43
- # @param [ Hash ] options The scoped assignment options.
44
- # @param [ Class ] type Optional class to build the document with.
42
+ # @overload build(attributes = {}, options = {}, type = nil)
43
+ # @param [ Hash ] attributes The attributes to build the document with.
44
+ # @param [ Hash ] options The scoped assignment options.
45
+ # @param [ Class ] type Optional class to build the document with.
46
+ #
47
+ # @overload build(attributes = {}, type = nil)
48
+ # @param [ Hash ] attributes The attributes to build the document with.
49
+ # @param [ Class ] type Optional class to build the document with.
45
50
  #
46
51
  # @return [ Document ] The new document.
47
52
  def build(attributes = {}, options = {}, type = nil)
53
+ if options.is_a? Class
54
+ options, type = {}, options
55
+ end
56
+
48
57
  Factory.build(type || metadata.klass, attributes, options).tap do |doc|
49
58
  doc.identify
50
59
  append(doc)
@@ -86,9 +95,14 @@ module Mongoid # :nodoc:
86
95
  # @example Create a new document in the relation.
87
96
  # person.movies.create(:name => "Bozo")
88
97
  #
89
- # @param [ Hash ] attributes The attributes to build the document with.
90
- # @param [ Hash ] options The scoped assignment options.
91
- # @param [ Class ] type Optional class to create the document with.
98
+ # @overload create(attributes = {}, options = {}, type = nil)
99
+ # @param [ Hash ] attributes The attributes to build the document with.
100
+ # @param [ Hash ] options The scoped assignment options.
101
+ # @param [ Class ] type Optional class to create the document with.
102
+ #
103
+ # @overload create(attributes = {}, type = nil)
104
+ # @param [ Hash ] attributes The attributes to build the document with.
105
+ # @param [ Class ] type Optional class to create the document with.
92
106
  #
93
107
  # @return [ Document ] The newly created document.
94
108
  def create(attributes = {}, options = {}, type = nil, &block)
@@ -102,9 +116,14 @@ module Mongoid # :nodoc:
102
116
  # @example Create the document.
103
117
  # person.addresses.create!(:street => "Unter der Linden")</tt>
104
118
  #
105
- # @param [ Hash ] attributes The attributes to build the document with.
106
- # @param [ Hash ] options The scoped assignment options.
107
- # @param [ Class ] type Optional class to create the document with.
119
+ # @overload create!(attributes = {}, options = {}, type = nil)
120
+ # @param [ Hash ] attributes The attributes to build the document with.
121
+ # @param [ Hash ] options The scoped assignment options.
122
+ # @param [ Class ] type Optional class to create the document with.
123
+ #
124
+ # @overload create!(attributes = {}, type = nil)
125
+ # @param [ Hash ] attributes The attributes to build the document with.
126
+ # @param [ Class ] type Optional class to create the document with.
108
127
  #
109
128
  # @raise [ Errors::Validations ] If a validation error occured.
110
129
  #
@@ -8,33 +8,23 @@ module Mongoid # :nodoc:
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  included do
11
- cattr_accessor :embedded
11
+ class_attribute :embedded, :instance_reader => false
12
12
  class_attribute :relations
13
13
  self.embedded = false
14
14
  self.relations = {}
15
-
16
- # For backwards compatibility, alias the class method for associations
17
- # and embedding as well. Fix in related gems.
18
- #
19
- # @todo Affected libraries: Machinist
20
- class << self
21
- alias :associations :relations
22
- alias :embedded? :embedded
23
- end
24
15
  end
25
16
 
26
- # Get the metadata for all the defined relations.
17
+ # This is convenience for librarys still on the old API.
27
18
  #
28
- # @note Refactored from using delegate for class load performance.
19
+ # @example Get the associations.
20
+ # person.associations
29
21
  #
30
- # @example Get the relations.
31
- # model.relations
22
+ # @return [ Hash ] The relations.
32
23
  #
33
- # @return [ Hash<String, Metadata> ] The relation metadata.
34
- def relations
35
- self.class.relations
24
+ # @since 2.3.1
25
+ def associations
26
+ self.relations
36
27
  end
37
- alias :associations :relations
38
28
 
39
29
  module ClassMethods #:nodoc:
40
30
 
@@ -113,7 +113,7 @@ module Mongoid # :nodoc:
113
113
  #
114
114
  # @since 2.0.0.rc.1
115
115
  def class_name
116
- @class_name ||= (self[:class_name] || classify)
116
+ @class_name ||= (self[:class_name] || classify).sub(/^::/,"")
117
117
  end
118
118
 
119
119
  # Get the foreign key contraint for the metadata.
@@ -202,10 +202,7 @@ module Mongoid # :nodoc:
202
202
  #
203
203
  # @since 2.2.0
204
204
  def eager_load(criteria)
205
- relation.eager_load(
206
- self,
207
- criteria.clone.tap { |crit| crit.inclusions.clear }
208
- )
205
+ relation.eager_load(self, criteria.clone)
209
206
  end
210
207
 
211
208
  # Will determine if the relation is an embedded one or not. Currently
@@ -11,18 +11,6 @@ module Mongoid # :nodoc:
11
11
  class_attribute :polymorphic
12
12
  end
13
13
 
14
- # Is the document in a polymorphic relation?
15
- #
16
- # @note Refactored from using delegate for class load performance.
17
- #
18
- # @example Is the document polymorphic?
19
- # model.polymorphic?
20
- #
21
- # @return [ true, false ] If the document is in a polymorphic relation.
22
- def polymorphic?
23
- self.class.polymorphic?
24
- end
25
-
26
14
  module ClassMethods #:nodoc:
27
15
 
28
16
  # Attempts to set up the information needed to handle a polymorphic
@@ -46,19 +34,6 @@ module Mongoid # :nodoc:
46
34
  end
47
35
  end
48
36
  end
49
-
50
- # Determines if the class is in a polymorphic relations, and thus must
51
- # store the _type field in the database.
52
- #
53
- # @example Check if the class is polymorphic.
54
- # Movie.polymorphic?
55
- #
56
- # @return [ true, false ] True if polymorphic, false if not.
57
- #
58
- # @since 2.0.0.rc.1
59
- def polymorphic?
60
- !!polymorphic
61
- end
62
37
  end
63
38
  end
64
39
  end
@@ -46,14 +46,23 @@ module Mongoid #:nodoc:
46
46
  # @example Build a new document on the relation.
47
47
  # person.posts.build(:title => "A new post")
48
48
  #
49
- # @param [ Hash ] attributes The attributes of the new document.
50
- # @param [ Hash ] options The scoped assignment options.
51
- # @param [ Class ] type The optional subclass to build.
49
+ # @overload build(attributes = {}, options = {}, type = nil)
50
+ # @param [ Hash ] attributes The attributes of the new document.
51
+ # @param [ Hash ] options The scoped assignment options.
52
+ # @param [ Class ] type The optional subclass to build.
53
+ #
54
+ # @overload build(attributes = {}, type = nil)
55
+ # @param [ Hash ] attributes The attributes of the new document.
56
+ # @param [ Class ] type The optional subclass to build.
52
57
  #
53
58
  # @return [ Document ] The new document.
54
59
  #
55
60
  # @since 2.0.0.beta.1
56
61
  def build(attributes = {}, options = {}, type = nil)
62
+ if options.is_a? Class
63
+ options, type = {}, options
64
+ end
65
+
57
66
  Factory.build(type || klass, attributes, options).tap do |doc|
58
67
  append(doc)
59
68
  yield(doc) if block_given?
@@ -67,9 +76,14 @@ module Mongoid #:nodoc:
67
76
  # @example Create and save the new document.
68
77
  # person.posts.create(:text => "Testing")
69
78
  #
70
- # @param [ Hash ] attributes The attributes to create with.
71
- # @param [ Hash ] options The scoped assignment options.
72
- # @param [ Class ] type The optional type of document to create.
79
+ # @overload create(attributes = nil, options = {}, type = nil)
80
+ # @param [ Hash ] attributes The attributes to create with.
81
+ # @param [ Hash ] options The scoped assignment options.
82
+ # @param [ Class ] type The optional type of document to create.
83
+ #
84
+ # @overload create(attributes = nil, type = nil)
85
+ # @param [ Hash ] attributes The attributes to create with.
86
+ # @param [ Class ] type The optional type of document to create.
73
87
  #
74
88
  # @return [ Document ] The newly created document.
75
89
  #
@@ -87,9 +101,14 @@ module Mongoid #:nodoc:
87
101
  # @example Create and save the new document.
88
102
  # person.posts.create!(:text => "Testing")
89
103
  #
90
- # @param [ Hash ] attributes The attributes to create with.
91
- # @param [ Hash ] options The scoped assignment options.
92
- # @param [ Class ] type The optional type of document to create.
104
+ # @overload create!(attributes = nil, options = {}, type = nil)
105
+ # @param [ Hash ] attributes The attributes to create with.
106
+ # @param [ Hash ] options The scoped assignment options.
107
+ # @param [ Class ] type The optional type of document to create.
108
+ #
109
+ # @overload create!(attributes = nil, type = nil)
110
+ # @param [ Hash ] attributes The attributes to create with.
111
+ # @param [ Class ] type The optional type of document to create.
93
112
  #
94
113
  # @raise [ Errors::Validations ] If validation failed.
95
114
  #
@@ -276,7 +295,7 @@ module Mongoid #:nodoc:
276
295
  tap do |proxy|
277
296
  if replacement != proxy.in_memory
278
297
  proxy.purge
279
- proxy.push(replacement.compact) if replacement
298
+ proxy.push(replacement.compact.uniq) if replacement
280
299
  end
281
300
  end
282
301
  end
@@ -54,14 +54,24 @@ module Mongoid # :nodoc:
54
54
  # @example Build a new document on the relation.
55
55
  # person.posts.build(:title => "A new post")
56
56
  #
57
- # @param [ Hash ] attributes The attributes of the new document.
58
- # @param [ Hash ] options The scoped assignment options.
59
- # @param [ Class ] type The optional subclass to build.
57
+ # @overload build(attributes = {}, options = {}, type = nil)
58
+ # @param [ Hash ] attributes The attributes of the new document.
59
+ # @param [ Hash ] options The scoped assignment options.
60
+ # @param [ Class ] type The optional subclass to build.
61
+ #
62
+ # @overload build(attributes = {}, type = nil)
63
+ # @param [ Hash ] attributes The attributes of the new document.
64
+ # @param [ Hash ] options The scoped assignment options.
65
+ # @param [ Class ] type The optional subclass to build.
60
66
  #
61
67
  # @return [ Document ] The new document.
62
68
  #
63
69
  # @since 2.0.0.beta.1
64
70
  def build(attributes = {}, options = {}, type = nil)
71
+ if options.is_a? Class
72
+ options, type = {}, options
73
+ end
74
+
65
75
  Factory.build(type || klass, attributes, options).tap do |doc|
66
76
  base.send(metadata.foreign_key).push(doc.id)
67
77
  append(doc)
@@ -44,7 +44,7 @@ module Mongoid #:nodoc:
44
44
  #
45
45
  # @since 2.1.0
46
46
  def <<(document)
47
- added << document
47
+ added.push(document)
48
48
  end
49
49
  alias :push :<<
50
50
 
@@ -151,12 +151,11 @@ module Mongoid #:nodoc:
151
151
  end
152
152
  else
153
153
  unloaded.each do |doc|
154
- loaded.push(doc)
154
+ loaded.push(added.delete_one(doc) || doc)
155
155
  yield(doc)
156
156
  end
157
157
  end
158
158
  added.each do |doc|
159
- next if doc.persisted? && (!loaded? && !loaded.empty?)
160
159
  yield(doc)
161
160
  end
162
161
  @executed = true
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc
3
- VERSION = "2.3.0"
3
+ VERSION = "2.3.1"
4
4
  end
@@ -24,18 +24,6 @@ module Mongoid #:nodoc:
24
24
  self.cyclic = true
25
25
  end
26
26
 
27
- # Get the maximum number of versions to store.
28
- #
29
- # @note Refactored from using delegate for class load performance.
30
- #
31
- # @example Get the max versions.
32
- # model.version_max
33
- #
34
- # @return [ Integer ] The max number of versions.
35
- def version_max
36
- self.class.version_max
37
- end
38
-
39
27
  # Create a new version of the +Document+. This will load the previous
40
28
  # document from the database and set it as the next version before saving
41
29
  # the current document. It then increments the version number. If a #max_versions
@@ -50,7 +38,7 @@ module Mongoid #:nodoc:
50
38
  if previous && versioned_attributes_changed?
51
39
  versions.build(previous.versioned_attributes).attributes.delete("_id")
52
40
  if version_max.present? && versions.length > version_max
53
- versions.shift
41
+ versions.delete(versions.first)
54
42
  end
55
43
  self.version = (version || 1 ) + 1
56
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-03 00:00:00.000000000Z
12
+ date: 2011-10-11 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
16
- requirement: &70134095171800 !ruby/object:Gem::Requirement
16
+ requirement: &70233415155800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70134095171800
24
+ version_requirements: *70233415155800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: tzinfo
27
- requirement: &70134095170860 !ruby/object:Gem::Requirement
27
+ requirement: &70233415154900 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.3.22
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70134095170860
35
+ version_requirements: *70233415154900
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mongo
38
- requirement: &70134095170140 !ruby/object:Gem::Requirement
38
+ requirement: &70233415153960 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '1.4'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70134095170140
46
+ version_requirements: *70233415153960
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
- requirement: &70134095169380 !ruby/object:Gem::Requirement
49
+ requirement: &70233415152900 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 3.5.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70134095169380
57
+ version_requirements: *70233415152900
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bson_ext
60
- requirement: &70134095168180 !ruby/object:Gem::Requirement
60
+ requirement: &70233415152060 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '1.4'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70134095168180
68
+ version_requirements: *70233415152060
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mocha
71
- requirement: &70134095167500 !ruby/object:Gem::Requirement
71
+ requirement: &70233415151220 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.9.12
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70134095167500
79
+ version_requirements: *70233415151220
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &70134095166120 !ruby/object:Gem::Requirement
82
+ requirement: &70233415150260 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '2.6'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70134095166120
90
+ version_requirements: *70233415150260
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: watchr
93
- requirement: &70134095164880 !ruby/object:Gem::Requirement
93
+ requirement: &70233415149060 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0.6'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70134095164880
101
+ version_requirements: *70233415149060
102
102
  description: Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written
103
103
  in Ruby.
104
104
  email:
@@ -173,6 +173,7 @@ files:
173
173
  - lib/mongoid/errors/invalid_field.rb
174
174
  - lib/mongoid/errors/invalid_find.rb
175
175
  - lib/mongoid/errors/invalid_options.rb
176
+ - lib/mongoid/errors/invalid_time.rb
176
177
  - lib/mongoid/errors/invalid_type.rb
177
178
  - lib/mongoid/errors/mixed_relations.rb
178
179
  - lib/mongoid/errors/mongoid_error.rb
@@ -196,6 +197,7 @@ files:
196
197
  - lib/mongoid/extensions/string/checks.rb
197
198
  - lib/mongoid/extensions/string/conversions.rb
198
199
  - lib/mongoid/extensions/string/inflections.rb
200
+ - lib/mongoid/extensions/symbol/checks.rb
199
201
  - lib/mongoid/extensions/symbol/inflections.rb
200
202
  - lib/mongoid/extensions/true_class/equality.rb
201
203
  - lib/mongoid/extensions.rb
@@ -389,7 +391,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
389
391
  version: '0'
390
392
  segments:
391
393
  - 0
392
- hash: -2142678717423572392
394
+ hash: 171855285831586391
393
395
  required_rubygems_version: !ruby/object:Gem::Requirement
394
396
  none: false
395
397
  requirements: