mongoid 6.1.0 → 6.1.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 (132) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mongoid/atomic.rb +3 -3
  3. data/lib/mongoid/attributes.rb +1 -2
  4. data/lib/mongoid/attributes/dynamic.rb +3 -2
  5. data/lib/mongoid/attributes/nested.rb +1 -1
  6. data/lib/mongoid/attributes/processing.rb +0 -4
  7. data/lib/mongoid/changeable.rb +1 -1
  8. data/lib/mongoid/clients/options.rb +1 -1
  9. data/lib/mongoid/composable.rb +3 -1
  10. data/lib/mongoid/contextual/atomic.rb +1 -1
  11. data/lib/mongoid/contextual/geo_near.rb +3 -2
  12. data/lib/mongoid/contextual/memory.rb +3 -3
  13. data/lib/mongoid/contextual/mongo.rb +5 -5
  14. data/lib/mongoid/contextual/none.rb +14 -2
  15. data/lib/mongoid/copyable.rb +1 -5
  16. data/lib/mongoid/criteria.rb +2 -2
  17. data/lib/mongoid/criteria/findable.rb +3 -2
  18. data/lib/mongoid/criteria/includable.rb +2 -2
  19. data/lib/mongoid/criteria/queryable/aggregable.rb +1 -1
  20. data/lib/mongoid/criteria/queryable/extensions/array.rb +1 -1
  21. data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -1
  22. data/lib/mongoid/criteria/queryable/extensions/hash.rb +4 -4
  23. data/lib/mongoid/criteria/queryable/extensions/object.rb +4 -4
  24. data/lib/mongoid/criteria/queryable/extensions/regexp.rb +34 -0
  25. data/lib/mongoid/criteria/queryable/options.rb +16 -0
  26. data/lib/mongoid/criteria/queryable/selector.rb +1 -1
  27. data/lib/mongoid/document.rb +1 -1
  28. data/lib/mongoid/errors/delete_restriction.rb +2 -2
  29. data/lib/mongoid/errors/inverse_not_found.rb +1 -1
  30. data/lib/mongoid/extensions/hash.rb +3 -2
  31. data/lib/mongoid/extensions/object.rb +2 -2
  32. data/lib/mongoid/extensions/time.rb +1 -1
  33. data/lib/mongoid/factory.rb +0 -1
  34. data/lib/mongoid/fields/foreign_key.rb +2 -2
  35. data/lib/mongoid/findable.rb +1 -1
  36. data/lib/mongoid/indexable.rb +3 -2
  37. data/lib/mongoid/indexable/specification.rb +1 -1
  38. data/lib/mongoid/interceptable.rb +3 -9
  39. data/lib/mongoid/loggable.rb +1 -1
  40. data/lib/mongoid/matchable.rb +16 -9
  41. data/lib/mongoid/matchable/all.rb +2 -2
  42. data/lib/mongoid/matchable/and.rb +3 -3
  43. data/lib/mongoid/matchable/default.rb +2 -2
  44. data/lib/mongoid/matchable/elem_match.rb +3 -3
  45. data/lib/mongoid/matchable/exists.rb +2 -2
  46. data/lib/mongoid/matchable/gt.rb +2 -2
  47. data/lib/mongoid/matchable/gte.rb +2 -2
  48. data/lib/mongoid/matchable/in.rb +2 -2
  49. data/lib/mongoid/matchable/lt.rb +2 -2
  50. data/lib/mongoid/matchable/lte.rb +2 -2
  51. data/lib/mongoid/matchable/ne.rb +2 -2
  52. data/lib/mongoid/matchable/nin.rb +2 -2
  53. data/lib/mongoid/matchable/or.rb +3 -3
  54. data/lib/mongoid/matchable/regexp.rb +27 -0
  55. data/lib/mongoid/matchable/size.rb +2 -2
  56. data/lib/mongoid/persistable.rb +0 -3
  57. data/lib/mongoid/persistable/creatable.rb +2 -4
  58. data/lib/mongoid/persistable/deletable.rb +1 -1
  59. data/lib/mongoid/persistable/settable.rb +1 -1
  60. data/lib/mongoid/persistable/upsertable.rb +1 -1
  61. data/lib/mongoid/persistence_context.rb +2 -3
  62. data/lib/mongoid/relations/accessors.rb +1 -2
  63. data/lib/mongoid/relations/bindings/embedded/in.rb +0 -4
  64. data/lib/mongoid/relations/bindings/embedded/many.rb +1 -8
  65. data/lib/mongoid/relations/bindings/embedded/one.rb +0 -10
  66. data/lib/mongoid/relations/bindings/referenced/many.rb +0 -4
  67. data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +4 -4
  68. data/lib/mongoid/relations/builders/embedded/one.rb +1 -1
  69. data/lib/mongoid/relations/builders/nested_attributes/many.rb +1 -1
  70. data/lib/mongoid/relations/conversions.rb +1 -1
  71. data/lib/mongoid/relations/counter_cache.rb +10 -10
  72. data/lib/mongoid/relations/eager.rb +6 -11
  73. data/lib/mongoid/relations/eager/base.rb +4 -4
  74. data/lib/mongoid/relations/embedded/batchable.rb +3 -3
  75. data/lib/mongoid/relations/embedded/in.rb +1 -3
  76. data/lib/mongoid/relations/embedded/many.rb +12 -9
  77. data/lib/mongoid/relations/embedded/one.rb +1 -3
  78. data/lib/mongoid/relations/macros.rb +3 -2
  79. data/lib/mongoid/relations/metadata.rb +3 -3
  80. data/lib/mongoid/relations/nested_builder.rb +1 -1
  81. data/lib/mongoid/relations/proxy.rb +3 -2
  82. data/lib/mongoid/relations/referenced/in.rb +1 -4
  83. data/lib/mongoid/relations/referenced/many.rb +5 -7
  84. data/lib/mongoid/relations/referenced/many_to_many.rb +2 -2
  85. data/lib/mongoid/relations/referenced/one.rb +0 -2
  86. data/lib/mongoid/relations/reflections.rb +2 -2
  87. data/lib/mongoid/relations/synchronization.rb +11 -11
  88. data/lib/mongoid/scopable.rb +2 -2
  89. data/lib/mongoid/serializable.rb +4 -3
  90. data/lib/mongoid/tasks/database.rb +2 -1
  91. data/lib/mongoid/threaded.rb +4 -4
  92. data/lib/mongoid/validatable.rb +1 -1
  93. data/lib/mongoid/validatable/macros.rb +4 -2
  94. data/lib/mongoid/version.rb +1 -1
  95. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +12 -2
  96. data/spec/app/models/book.rb +2 -1
  97. data/spec/app/models/page.rb +1 -1
  98. data/spec/mongoid/contextual/none_spec.rb +15 -0
  99. data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +89 -0
  100. data/spec/mongoid/criteria/queryable/selectable_spec.rb +15 -0
  101. data/spec/mongoid/criteria_spec.rb +6 -2
  102. data/spec/mongoid/interceptable_spec.rb +19 -0
  103. data/spec/mongoid/matchable/all_spec.rb +4 -4
  104. data/spec/mongoid/matchable/and_spec.rb +10 -10
  105. data/spec/mongoid/matchable/default_spec.rb +12 -12
  106. data/spec/mongoid/matchable/elem_match_spec.rb +11 -11
  107. data/spec/mongoid/matchable/exists_spec.rb +5 -5
  108. data/spec/mongoid/matchable/gt_spec.rb +8 -8
  109. data/spec/mongoid/matchable/gte_spec.rb +8 -8
  110. data/spec/mongoid/matchable/in_spec.rb +5 -5
  111. data/spec/mongoid/matchable/lt_spec.rb +8 -8
  112. data/spec/mongoid/matchable/lte_spec.rb +8 -8
  113. data/spec/mongoid/matchable/ne_spec.rb +5 -5
  114. data/spec/mongoid/matchable/nin_spec.rb +5 -5
  115. data/spec/mongoid/matchable/or_spec.rb +7 -7
  116. data/spec/mongoid/matchable/regexp_spec.rb +59 -0
  117. data/spec/mongoid/matchable/size_spec.rb +3 -3
  118. data/spec/mongoid/matchable_spec.rb +108 -58
  119. data/spec/mongoid/persistable/deletable_spec.rb +15 -0
  120. data/spec/mongoid/persistable/settable_spec.rb +16 -0
  121. data/spec/mongoid/persistence_context_spec.rb +22 -1
  122. data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +4 -4
  123. data/spec/mongoid/relations/embedded/many_spec.rb +24 -6
  124. data/spec/mongoid/relations/referenced/many_to_many_spec.rb +1 -1
  125. data/spec/mongoid/relations/synchronization_spec.rb +48 -2
  126. data/spec/mongoid/relations/touchable_spec.rb +40 -0
  127. data/spec/mongoid/validatable/uniqueness_spec.rb +2 -0
  128. data/spec/spec_helper.rb +1 -1
  129. metadata +9 -26
  130. checksums.yaml.gz.sig +0 -0
  131. data.tar.gz.sig +0 -1
  132. metadata.gz.sig +0 -1
@@ -12,8 +12,8 @@ module Mongoid
12
12
  # @example Create the new belongs to eager load preloader.
13
13
  # BelongsTo.new(relations_metadata, parent_docs)
14
14
  #
15
- # @param [ Array<Metadata> ] Relations to eager load
16
- # @param [ Array<Document> ] Documents to preload the relations
15
+ # @param [ Array<Metadata> ] associations Relations to eager load
16
+ # @param [ Array<Document> ] docs Documents to preload the relations
17
17
  #
18
18
  # @return [ Base ] The eager load preloader
19
19
  #
@@ -84,7 +84,7 @@ module Mongoid
84
84
  # @example Set docs into parent with pk = "foo"
85
85
  # loader.set_on_parent("foo", docs)
86
86
  #
87
- # @param [ ObjectId ] parent`s id
87
+ # @param [ ObjectId ] id parent`s id
88
88
  # @param [ Document, Array ] element to push into the parent
89
89
  #
90
90
  # @since 4.0.0
@@ -140,7 +140,7 @@ module Mongoid
140
140
  # @example Set docs into parent using the current relation name.
141
141
  # loader.set_relation(doc, docs)
142
142
  #
143
- # @param [ Document ] document
143
+ # @param [ Document ] doc
144
144
  # @param [ Document, Array ] element to set into the parent
145
145
  #
146
146
  # @since 4.0.0
@@ -85,7 +85,7 @@ module Mongoid
85
85
  else
86
86
  batch_remove(target.dup)
87
87
  end
88
- else
88
+ elsif target != docs
89
89
  base.delayed_atomic_sets.clear unless _assigning?
90
90
  docs = normalize_docs(docs).compact
91
91
  target.clear and _unscoped.clear
@@ -279,7 +279,7 @@ module Mongoid
279
279
  self.inserts_valid = false
280
280
  end
281
281
  end
282
- doc.as_document
282
+ doc.send(:as_attributes)
283
283
  end
284
284
  end
285
285
 
@@ -308,7 +308,7 @@ module Mongoid
308
308
  _unscoped.delete_one(doc)
309
309
  unbind_one(doc)
310
310
  execute_callback :after_remove, doc
311
- doc.as_document
311
+ doc.send(:as_attributes)
312
312
  end
313
313
  end
314
314
 
@@ -43,7 +43,7 @@ module Mongoid
43
43
  # @example Substitute the new document.
44
44
  # person.name.substitute(new_name)
45
45
  #
46
- # @param [ Document ] other A document to replace the target.
46
+ # @param [ Document ] replacement A document to replace the target.
47
47
  #
48
48
  # @return [ Document, nil ] The relation or nil.
49
49
  #
@@ -67,8 +67,6 @@ module Mongoid
67
67
  # @example Get the binding.
68
68
  # binding([ address ])
69
69
  #
70
- # @param [ Proxy ] new_target The new documents to bind with.
71
- #
72
70
  # @return [ Binding ] A binding object.
73
71
  #
74
72
  # @since 2.0.0.rc.1
@@ -36,7 +36,8 @@ module Mongoid
36
36
  # @example Push a document.
37
37
  # person.addresses.push(address)
38
38
  #
39
- # @param [ Document, Array<Document> ] *args Any number of documents.
39
+ # @param [ Document, Array<Document> ] args Any number of documents.
40
+ #
40
41
  def <<(*args)
41
42
  docs = args.flatten
42
43
  return concat(docs) if docs.size > 1
@@ -57,11 +58,7 @@ module Mongoid
57
58
  #
58
59
  # @since 2.0.0.rc.1
59
60
  def as_document
60
- attributes = []
61
- _unscoped.each do |doc|
62
- attributes.push(doc.as_document)
63
- end
64
- attributes
61
+ as_attributes.collect { |attrs| BSON::Document.new(attrs) }
65
62
  end
66
63
 
67
64
  # Appends an array of documents to the relation. Performs a batch
@@ -354,8 +351,6 @@ module Mongoid
354
351
  # @example Create the binding.
355
352
  # relation.binding([ address ])
356
353
  #
357
- # @param [ Array<Document> ] new_target The new documents to bind with.
358
- #
359
354
  # @return [ Binding ] The many binding.
360
355
  #
361
356
  # @since 2.0.0.rc.1
@@ -478,7 +473,7 @@ module Mongoid
478
473
  # relation.remove_all({ :num => 1 }, true)
479
474
  #
480
475
  # @param [ Hash ] conditions Conditions to filter by.
481
- # @param [ true, false ] destroy If true then destroy, else delete.
476
+ # @param [ true, false ] method
482
477
  #
483
478
  # @return [ Integer ] The number of documents removed.
484
479
  def remove_all(conditions = {}, method = :delete)
@@ -514,6 +509,14 @@ module Mongoid
514
509
  @_unscoped = docs
515
510
  end
516
511
 
512
+ def as_attributes
513
+ attributes = []
514
+ _unscoped.each do |doc|
515
+ attributes.push(doc.as_document)
516
+ end
517
+ attributes
518
+ end
519
+
517
520
  class << self
518
521
 
519
522
  # Return the builder that is responsible for generating the documents
@@ -44,7 +44,7 @@ module Mongoid
44
44
  # @example Substitute the new document.
45
45
  # person.name.substitute(new_name)
46
46
  #
47
- # @param [ Document ] other A document to replace the target.
47
+ # @param [ Document ] replacement A document to replace the target.
48
48
  #
49
49
  # @return [ Document, nil ] The relation or nil.
50
50
  #
@@ -74,8 +74,6 @@ module Mongoid
74
74
  # @example Get the binding.
75
75
  # relation.binding([ address ])
76
76
  #
77
- # @param [ Document ] new_target The new document to bind with.
78
- #
79
77
  # @return [ Binding ] The relation's binding.
80
78
  #
81
79
  # @since 2.0.0.rc.1
@@ -198,7 +198,7 @@ module Mongoid
198
198
  reference(meta, Array)
199
199
  autosave(meta)
200
200
  validates_relation(meta)
201
- synced(meta)
201
+ _synced(meta)
202
202
  meta
203
203
  end
204
204
 
@@ -327,7 +327,8 @@ module Mongoid
327
327
  # Model.reference_one_to_one(:name, meta)
328
328
  #
329
329
  # @param [ Symbol ] name The name of the relation.
330
- # @param [ Metadata ] meta The relation metadata.
330
+ # @param [ Symbol ] options The association options.
331
+ # @param [ Metadata ] relation The relation.
331
332
  #
332
333
  # @return [ Class ] The model class.
333
334
  #
@@ -920,7 +920,7 @@ module Mongoid
920
920
  # @example Find the module from the parts.
921
921
  # metadata.find_from_parts([ "Namespace", "Module" ])
922
922
  #
923
- # @param [ Array<String> ] The modules.
923
+ # @param [ Array<String> ] modules The modules.
924
924
  #
925
925
  # @return [ String ] The matching module.
926
926
  #
@@ -1127,7 +1127,7 @@ module Mongoid
1127
1127
  # @example Find the inverses.
1128
1128
  # metadata.lookup_inverses(other)
1129
1129
  #
1130
- # @param [ Document ] : The inverse document.
1130
+ # @param [ Document ] other The inverse document.
1131
1131
  #
1132
1132
  # @return [ Array<String> ] The inverse names.
1133
1133
  def lookup_inverses(other)
@@ -1150,7 +1150,7 @@ module Mongoid
1150
1150
  # @example Find the inverse.
1151
1151
  # metadata.lookup_inverse(other)
1152
1152
  #
1153
- # @param [ Document ] : The inverse document.
1153
+ # @param [ Document ] other The inverse document.
1154
1154
  #
1155
1155
  # @return [ String ] The inverse name.
1156
1156
  #
@@ -25,7 +25,7 @@ module Mongoid
25
25
  # @example Is there a reject proc?
26
26
  # builder.reject?
27
27
  #
28
- # @param The parent document of the relation
28
+ # @param [ Document ] document The parent document of the relation
29
29
  # @param [ Hash ] attrs The attributes to check for rejection.
30
30
  #
31
31
  # @return [ true, false ] True and call proc or method if rejectable, false if not.
@@ -115,7 +115,8 @@ module Mongoid
115
115
  # to the target of the proxy. This can be overridden in special cases.
116
116
  #
117
117
  # @param [ String, Symbol ] name The name of the method.
118
- # @param [ Array ] *args The arguments passed to the method.
118
+ # @param [ Array ] args The arguments passed to the method.
119
+ #
119
120
  def method_missing(name, *args, &block)
120
121
  target.send(name, *args, &block)
121
122
  end
@@ -153,7 +154,7 @@ module Mongoid
153
154
  # @example returns the before_add callback method name
154
155
  # callback_method(:before_add)
155
156
  #
156
- # @param [ Symbol ] which callback
157
+ # @param [ Symbol ] callback_name Which callback
157
158
  #
158
159
  # @return [ Array ] with callback methods to be executed, the array may have symbols and Procs
159
160
  #
@@ -62,8 +62,7 @@ module Mongoid
62
62
  # @example Substitute the relation.
63
63
  # name.substitute(new_name)
64
64
  #
65
- # @param [ Document, Array<Document> ] new_target The replacement.
66
- # @param [ true, false ] building Are we in build mode?
65
+ # @param [ Document, Array<Document> ] replacement The replacement.
67
66
  #
68
67
  # @return [ In, nil ] The relation or nil.
69
68
  #
@@ -83,8 +82,6 @@ module Mongoid
83
82
  # @example Get the binding object.
84
83
  # binding([ address ])
85
84
  #
86
- # @param [ Document, Array<Document> ] new_target The replacement.
87
- #
88
85
  # @return [ Binding ] The binding object.
89
86
  #
90
87
  # @since 2.0.0.rc.1
@@ -40,7 +40,7 @@ module Mongoid
40
40
  # @example Concat with other documents.
41
41
  # person.posts.concat([ post_one, post_two ])
42
42
  #
43
- # @param [ Document, Array<Document> ] *args Any number of documents.
43
+ # @param [ Document, Array<Document> ] args Any number of documents.
44
44
  #
45
45
  # @return [ Array<Document> ] The loaded docs.
46
46
  #
@@ -208,7 +208,7 @@ module Mongoid
208
208
  # @note This will keep matching documents in memory for iteration
209
209
  # later.
210
210
  #
211
- # @param [ BSON::ObjectId, Array<BSON::ObjectId> ] arg The ids.
211
+ # @param [ BSON::ObjectId, Array<BSON::ObjectId> ] args The ids.
212
212
  #
213
213
  # @return [ Document, Criteria ] The matching document(s).
214
214
  #
@@ -385,8 +385,6 @@ module Mongoid
385
385
  # @example Get the binding.
386
386
  # relation.binding([ address ])
387
387
  #
388
- # @param [ Array<Document> ] new_target The new documents to bind with.
389
- #
390
388
  # @return [ Binding ] The binding.
391
389
  #
392
390
  # @since 2.0.0.rc.1
@@ -510,7 +508,7 @@ module Mongoid
510
508
  # person.posts.delete_all({ :title => "Testing" })
511
509
  #
512
510
  # @param [ Hash ] conditions Optional conditions to delete with.
513
- # @param [ Symbol ] The deletion method to call.
511
+ # @param [ Symbol ] method The deletion method to call.
514
512
  #
515
513
  # @return [ Integer ] The number of documents deleted.
516
514
  #
@@ -519,7 +517,7 @@ module Mongoid
519
517
  selector = conditions || {}
520
518
  removed = klass.send(method, selector.merge!(criteria.selector))
521
519
  target.delete_if do |doc|
522
- if doc.matches?(selector)
520
+ if doc._matches?(selector)
523
521
  unbind_one(doc) and true
524
522
  end
525
523
  end
@@ -569,7 +567,7 @@ module Mongoid
569
567
  if doc.new_record? && doc.valid?(:create)
570
568
  doc.run_before_callbacks(:save, :create)
571
569
  docs.push(doc)
572
- inserts.push(doc.as_document)
570
+ inserts.push(doc.send(:as_attributes))
573
571
  else
574
572
  doc.save
575
573
  end
@@ -37,7 +37,7 @@ module Mongoid
37
37
  # @example Concat with other documents.
38
38
  # person.posts.concat([ post_one, post_two ])
39
39
  #
40
- # @param [ Document, Array<Document> ] *args Any number of documents.
40
+ # @param [ Document, Array<Document> ] args Any number of documents.
41
41
  #
42
42
  # @return [ Array<Document> ] The loaded docs.
43
43
  #
@@ -284,7 +284,7 @@ module Mongoid
284
284
  #
285
285
  # @since 3.0.0
286
286
  def unsynced(doc, key)
287
- doc.synced[key] = false
287
+ doc._synced[key] = false
288
288
  true
289
289
  end
290
290
 
@@ -83,8 +83,6 @@ module Mongoid
83
83
  # @example Get the binding.
84
84
  # relation.binding([ address ])
85
85
  #
86
- # @param [ Document ] new_target The new target of the relation.
87
- #
88
86
  # @return [ Binding ] The binding object.
89
87
  def binding
90
88
  Bindings::Referenced::One.new(base, target, __metadata)
@@ -24,7 +24,7 @@ module Mongoid
24
24
  # @example Find multiple relation metadata by macro.
25
25
  # person.reflect_on_all_associations(:embeds_many)
26
26
  #
27
- # @param [ Array<Symbol> ] *macros The relation macros.
27
+ # @param [ Array<Symbol> ] macros The relation macros.
28
28
  #
29
29
  # @return [ Array<Metadata> ] The matching relation metadata.
30
30
  def reflect_on_all_associations(*macros)
@@ -50,7 +50,7 @@ module Mongoid
50
50
  # @example Find multiple relation metadata by macro.
51
51
  # Person.reflect_on_all_associations(:embeds_many)
52
52
  #
53
- # @param [ Array<Symbol> ] *macros The relation macros.
53
+ # @param [ Array<Symbol> ] macros The relation macros.
54
54
  #
55
55
  # @return [ Array<Metadata> ] The matching relation metadata.
56
56
  def reflect_on_all_associations(*macros)
@@ -11,41 +11,41 @@ module Mongoid
11
11
  # the key has changed and the relation bindings have not been run.
12
12
  #
13
13
  # @example Are the foreign keys syncable?
14
- # document.syncable?(metadata)
14
+ # document._syncable??(metadata)
15
15
  #
16
16
  # @param [ Metadata ] metadata The relation metadata.
17
17
  #
18
18
  # @return [ true, false ] If we can sync.
19
19
  #
20
20
  # @since 2.1.0
21
- def syncable?(metadata)
22
- !synced?(metadata.foreign_key) && send(metadata.foreign_key_check)
21
+ def _syncable?(metadata)
22
+ !_synced?(metadata.foreign_key) && send(metadata.foreign_key_check)
23
23
  end
24
24
 
25
25
  # Get the synced foreign keys.
26
26
  #
27
27
  # @example Get the synced foreign keys.
28
- # document.synced
28
+ # document._synced
29
29
  #
30
30
  # @return [ Hash ] The synced foreign keys.
31
31
  #
32
32
  # @since 2.1.0
33
- def synced
34
- @synced ||= {}
33
+ def _synced
34
+ @_synced ||= {}
35
35
  end
36
36
 
37
37
  # Has the document been synced for the foreign key?
38
38
  #
39
39
  # @example Has the document been synced?
40
- # document.synced?
40
+ # document._synced??
41
41
  #
42
42
  # @param [ String ] foreign_key The foreign key.
43
43
  #
44
44
  # @return [ true, false ] If we can sync.
45
45
  #
46
46
  # @since 2.1.0
47
- def synced?(foreign_key)
48
- !!synced[foreign_key]
47
+ def _synced?(foreign_key)
48
+ !!_synced[foreign_key]
49
49
  end
50
50
 
51
51
  # Update the inverse keys on destroy.
@@ -110,7 +110,7 @@ module Mongoid
110
110
  # @param [ Metadata ] metadata The relation metadata.
111
111
  #
112
112
  # @since 2.1.0
113
- def synced(metadata)
113
+ def _synced(metadata)
114
114
  unless metadata.forced_nil_inverse?
115
115
  synced_save(metadata)
116
116
  synced_destroy(metadata)
@@ -137,7 +137,7 @@ module Mongoid
137
137
  set_callback(
138
138
  :save,
139
139
  :after,
140
- if: ->(doc){ doc.syncable?(metadata) }
140
+ if: ->(doc){ doc._syncable?(metadata) }
141
141
  ) do |doc|
142
142
  doc.update_inverse_keys(metadata)
143
143
  end
@@ -80,7 +80,7 @@ module Mongoid
80
80
  # default_scope ->{ where(active: true) }
81
81
  # end
82
82
  #
83
- # @param [ Proc, Criteria ] scope The default scope.
83
+ # @param [ Proc, Criteria ] value The default scope.
84
84
  #
85
85
  # @raise [ Errors::InvalidScope ] If the scope is not a proc or criteria.
86
86
  #
@@ -136,7 +136,7 @@ module Mongoid
136
136
  # end
137
137
  #
138
138
  # @param [ Symbol ] name The name of the scope.
139
- # @param [ Proc ] conditions The conditions of the scope.
139
+ # @param [ Proc ] value The conditions of the scope.
140
140
  #
141
141
  # @raise [ Errors::InvalidScope ] If the scope is not a proc.
142
142
  # @raise [ Errors::ScopeOverwrite ] If the scope name already exists.
@@ -66,7 +66,7 @@ module Mongoid
66
66
  #
67
67
  # @since 3.0.0
68
68
  def field_names(options)
69
- names = (as_document.keys + attribute_names).uniq.sort
69
+ names = (as_attributes.keys + attribute_names).uniq.sort
70
70
 
71
71
  only = Array.wrap(options[:only]).map(&:to_s)
72
72
  except = Array.wrap(options[:except]).map(&:to_s)
@@ -138,7 +138,7 @@ module Mongoid
138
138
  # @example Get the relation names.
139
139
  # document.relation_names(:include => [ :addresses ])
140
140
  #
141
- # @param [ Hash, Symbol, Array<Symbol ] inclusions The inclusions.
141
+ # @param [ Hash, Symbol, Array<Symbol> ] inclusions The inclusions.
142
142
  #
143
143
  # @return [ Array<Symbol> ] The names of the included relations.
144
144
  #
@@ -153,7 +153,8 @@ module Mongoid
153
153
  # @example Get the relation options.
154
154
  # document.relation_names(:include => [ :addresses ])
155
155
  #
156
- # @param [ Hash, Symbol, Array<Symbol ] inclusions The inclusions.
156
+ # @param [ Hash, Symbol, Array<Symbol> ] inclusions The inclusions.
157
+ # @param [ Hash ] options The options.
157
158
  # @param [ Symbol ] name The name of the relation.
158
159
  #
159
160
  # @return [ Hash ] The options for the relation.