mongoid 2.0.0.beta.20 → 2.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. data/README.rdoc +8 -0
  2. data/Rakefile +51 -0
  3. data/lib/config/locales/nl.yml +39 -0
  4. data/lib/config/locales/ro.yml +1 -1
  5. data/lib/mongoid.rb +17 -17
  6. data/lib/mongoid/atomicity.rb +54 -22
  7. data/lib/mongoid/attributes.rb +145 -125
  8. data/lib/mongoid/callbacks.rb +7 -2
  9. data/lib/mongoid/collection.rb +49 -32
  10. data/lib/mongoid/collections.rb +0 -1
  11. data/lib/mongoid/components.rb +34 -29
  12. data/lib/mongoid/config.rb +207 -193
  13. data/lib/mongoid/config/database.rb +167 -0
  14. data/lib/mongoid/contexts.rb +2 -5
  15. data/lib/mongoid/contexts/enumerable.rb +30 -4
  16. data/lib/mongoid/contexts/ids.rb +2 -2
  17. data/lib/mongoid/contexts/mongo.rb +30 -5
  18. data/lib/mongoid/copyable.rb +44 -0
  19. data/lib/mongoid/criteria.rb +110 -56
  20. data/lib/mongoid/criterion/creational.rb +34 -0
  21. data/lib/mongoid/criterion/destructive.rb +37 -0
  22. data/lib/mongoid/criterion/exclusion.rb +3 -1
  23. data/lib/mongoid/criterion/inclusion.rb +59 -64
  24. data/lib/mongoid/criterion/inspection.rb +22 -0
  25. data/lib/mongoid/criterion/optional.rb +42 -54
  26. data/lib/mongoid/criterion/selector.rb +9 -0
  27. data/lib/mongoid/default_scope.rb +28 -0
  28. data/lib/mongoid/deprecation.rb +5 -5
  29. data/lib/mongoid/dirty.rb +4 -5
  30. data/lib/mongoid/document.rb +161 -114
  31. data/lib/mongoid/extensions.rb +7 -11
  32. data/lib/mongoid/extensions/array/parentization.rb +2 -2
  33. data/lib/mongoid/extensions/date/conversions.rb +1 -1
  34. data/lib/mongoid/extensions/hash/conversions.rb +0 -23
  35. data/lib/mongoid/extensions/nil/collectionization.rb +12 -0
  36. data/lib/mongoid/extensions/object/reflections.rb +17 -0
  37. data/lib/mongoid/extensions/object/yoda.rb +27 -0
  38. data/lib/mongoid/extensions/string/conversions.rb +23 -4
  39. data/lib/mongoid/extensions/time_conversions.rb +4 -4
  40. data/lib/mongoid/field.rb +30 -19
  41. data/lib/mongoid/fields.rb +15 -5
  42. data/lib/mongoid/finders.rb +19 -11
  43. data/lib/mongoid/hierarchy.rb +34 -28
  44. data/lib/mongoid/identity.rb +62 -20
  45. data/lib/mongoid/inspection.rb +58 -0
  46. data/lib/mongoid/matchers.rb +20 -0
  47. data/lib/mongoid/multi_database.rb +11 -0
  48. data/lib/mongoid/nested_attributes.rb +41 -0
  49. data/lib/mongoid/paranoia.rb +3 -4
  50. data/lib/mongoid/paths.rb +1 -1
  51. data/lib/mongoid/persistence.rb +89 -90
  52. data/lib/mongoid/persistence/command.rb +20 -4
  53. data/lib/mongoid/persistence/insert.rb +13 -11
  54. data/lib/mongoid/persistence/insert_embedded.rb +8 -6
  55. data/lib/mongoid/persistence/remove.rb +6 -4
  56. data/lib/mongoid/persistence/remove_all.rb +6 -4
  57. data/lib/mongoid/persistence/remove_embedded.rb +8 -6
  58. data/lib/mongoid/persistence/update.rb +12 -10
  59. data/lib/mongoid/railtie.rb +2 -2
  60. data/lib/mongoid/railties/database.rake +10 -9
  61. data/lib/mongoid/relations.rb +104 -0
  62. data/lib/mongoid/relations/accessors.rb +154 -0
  63. data/lib/mongoid/relations/auto_save.rb +34 -0
  64. data/lib/mongoid/relations/binding.rb +24 -0
  65. data/lib/mongoid/relations/bindings.rb +9 -0
  66. data/lib/mongoid/relations/bindings/embedded/in.rb +77 -0
  67. data/lib/mongoid/relations/bindings/embedded/many.rb +93 -0
  68. data/lib/mongoid/relations/bindings/embedded/one.rb +65 -0
  69. data/lib/mongoid/relations/bindings/referenced/in.rb +78 -0
  70. data/lib/mongoid/relations/bindings/referenced/many.rb +93 -0
  71. data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +94 -0
  72. data/lib/mongoid/relations/bindings/referenced/one.rb +63 -0
  73. data/lib/mongoid/relations/builder.rb +41 -0
  74. data/lib/mongoid/relations/builders.rb +79 -0
  75. data/lib/mongoid/relations/builders/embedded/in.rb +25 -0
  76. data/lib/mongoid/relations/builders/embedded/many.rb +32 -0
  77. data/lib/mongoid/relations/builders/embedded/one.rb +26 -0
  78. data/lib/mongoid/relations/builders/nested_attributes/many.rb +116 -0
  79. data/lib/mongoid/relations/builders/nested_attributes/one.rb +135 -0
  80. data/lib/mongoid/relations/builders/referenced/in.rb +32 -0
  81. data/lib/mongoid/relations/builders/referenced/many.rb +26 -0
  82. data/lib/mongoid/relations/builders/referenced/many_to_many.rb +29 -0
  83. data/lib/mongoid/relations/builders/referenced/one.rb +30 -0
  84. data/lib/mongoid/relations/cascading.rb +55 -0
  85. data/lib/mongoid/relations/cascading/delete.rb +19 -0
  86. data/lib/mongoid/relations/cascading/destroy.rb +19 -0
  87. data/lib/mongoid/relations/cascading/nullify.rb +18 -0
  88. data/lib/mongoid/relations/cascading/strategy.rb +26 -0
  89. data/lib/mongoid/relations/cyclic.rb +97 -0
  90. data/lib/mongoid/relations/embedded/in.rb +172 -0
  91. data/lib/mongoid/relations/embedded/many.rb +450 -0
  92. data/lib/mongoid/relations/embedded/one.rb +169 -0
  93. data/lib/mongoid/relations/macros.rb +302 -0
  94. data/lib/mongoid/relations/many.rb +185 -0
  95. data/lib/mongoid/relations/metadata.rb +529 -0
  96. data/lib/mongoid/relations/nested_builder.rb +52 -0
  97. data/lib/mongoid/relations/one.rb +29 -0
  98. data/lib/mongoid/relations/polymorphic.rb +54 -0
  99. data/lib/mongoid/relations/proxy.rb +122 -0
  100. data/lib/mongoid/relations/referenced/in.rb +214 -0
  101. data/lib/mongoid/relations/referenced/many.rb +358 -0
  102. data/lib/mongoid/relations/referenced/many_to_many.rb +379 -0
  103. data/lib/mongoid/relations/referenced/one.rb +204 -0
  104. data/lib/mongoid/relations/reflections.rb +45 -0
  105. data/lib/mongoid/safe.rb +11 -1
  106. data/lib/mongoid/safety.rb +122 -97
  107. data/lib/mongoid/scope.rb +14 -9
  108. data/lib/mongoid/state.rb +37 -3
  109. data/lib/mongoid/timestamps.rb +11 -0
  110. data/lib/mongoid/validations.rb +42 -3
  111. data/lib/mongoid/validations/associated.rb +8 -5
  112. data/lib/mongoid/validations/uniqueness.rb +23 -2
  113. data/lib/mongoid/version.rb +1 -1
  114. data/lib/mongoid/versioning.rb +25 -16
  115. data/lib/rails/generators/mongoid/model/templates/model.rb +3 -1
  116. metadata +95 -80
  117. data/lib/mongoid/associations.rb +0 -364
  118. data/lib/mongoid/associations/embedded_in.rb +0 -74
  119. data/lib/mongoid/associations/embeds_many.rb +0 -299
  120. data/lib/mongoid/associations/embeds_one.rb +0 -111
  121. data/lib/mongoid/associations/foreign_key.rb +0 -35
  122. data/lib/mongoid/associations/meta_data.rb +0 -38
  123. data/lib/mongoid/associations/options.rb +0 -78
  124. data/lib/mongoid/associations/proxy.rb +0 -60
  125. data/lib/mongoid/associations/referenced_in.rb +0 -70
  126. data/lib/mongoid/associations/references_many.rb +0 -254
  127. data/lib/mongoid/associations/references_many_as_array.rb +0 -128
  128. data/lib/mongoid/associations/references_one.rb +0 -104
  129. data/lib/mongoid/extensions/array/accessors.rb +0 -17
  130. data/lib/mongoid/extensions/array/assimilation.rb +0 -26
  131. data/lib/mongoid/extensions/hash/accessors.rb +0 -42
  132. data/lib/mongoid/extensions/hash/assimilation.rb +0 -40
  133. data/lib/mongoid/extensions/nil/assimilation.rb +0 -17
  134. data/lib/mongoid/memoization.rb +0 -33
@@ -26,6 +26,26 @@ module Mongoid #:nodoc:
26
26
  #
27
27
  # <tt>DeleteAll.new(Person, { :validate => true }, {})</tt>
28
28
  def initialize(document_or_class, options = {}, selector = {})
29
+ init(document_or_class)
30
+ validate = options[:validate]
31
+ @validate = (validate.nil? ? true : validate)
32
+ @selector = selector
33
+ @options = { :safe => safe_mode?(options) }
34
+ end
35
+
36
+ private
37
+
38
+ # Setup the proper instance variables based on if the supplied argument
39
+ # was a document object or a class object.
40
+ #
41
+ # Example:
42
+ #
43
+ # <tt>init(document_or_class)</tt>
44
+ #
45
+ # Options:
46
+ #
47
+ # document_or_class: A document or a class.
48
+ def init(document_or_class)
29
49
  if document_or_class.is_a?(Mongoid::Document)
30
50
  @document = document_or_class
31
51
  @collection = @document.embedded? ? @document._root.collection : @document.collection
@@ -33,10 +53,6 @@ module Mongoid #:nodoc:
33
53
  @klass = document_or_class
34
54
  @collection = @klass.collection
35
55
  end
36
- validate = options[:validate]
37
- @selector = selector
38
- @validate = (validate.nil? ? true : validate)
39
- @options = { :safe => safe_mode?(options) }
40
56
  end
41
57
  end
42
58
  end
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Persistence #:nodoc:
4
+
4
5
  # Insert is a persistence command responsible for taking a document that
5
6
  # has not been saved to the database and saving it.
6
7
  #
@@ -11,6 +12,7 @@ module Mongoid #:nodoc:
11
12
  # false
12
13
  # );
13
14
  class Insert < Command
15
+
14
16
  # Insert the new document in the database. This delegates to the standard
15
17
  # MongoDB collection's insert command.
16
18
  #
@@ -22,28 +24,28 @@ module Mongoid #:nodoc:
22
24
  #
23
25
  # The +Document+, whether the insert succeeded or not.
24
26
  def persist
25
- return @document if @validate && @document.invalid?(:create)
26
- @document.run_callbacks(:create) do
27
- @document.run_callbacks(:save) do
27
+ return document if validate && document.invalid?(:create)
28
+ document.run_callbacks(:create) do
29
+ document.run_callbacks(:save) do
28
30
  if insert
29
- @document.new_record = false
30
- @document._children.each { |child| child.new_record = false }
31
- @document.move_changes
31
+ document.new_record = false
32
+ document._children.each { |child| child.new_record = false }
33
+ document.move_changes
32
34
  end
33
35
  end
34
- end; @document
36
+ end; document
35
37
  end
36
38
 
37
39
  protected
38
40
  # Insert the document into the database.
39
41
  def insert
40
- if @document.embedded?
42
+ if document.embedded?
41
43
  Persistence::InsertEmbedded.new(
42
- @document,
43
- @options.merge(:validate => @validate)
44
+ document,
45
+ options.merge(:validate => validate)
44
46
  ).persist
45
47
  else
46
- @collection.insert(@document.raw_attributes, @options)
48
+ collection.insert(document.to_hash, options)
47
49
  end
48
50
  end
49
51
  end
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Persistence #:nodoc:
4
+
4
5
  # Insert is a persistence command responsible for taking a document that
5
6
  # has not been saved to the database and saving it. This specific class
6
7
  # handles the case when the document is embedded in another.
@@ -12,6 +13,7 @@ module Mongoid #:nodoc:
12
13
  # false
13
14
  # );
14
15
  class InsertEmbedded < Command
16
+
15
17
  # Insert the new document in the database. If the document's parent is a
16
18
  # new record, we will call save on the parent, otherwise we will $push
17
19
  # the document onto the parent.
@@ -24,16 +26,16 @@ module Mongoid #:nodoc:
24
26
  #
25
27
  # The +Document+, whether the insert succeeded or not.
26
28
  def persist
27
- return @document if @validate && @document.invalid?(:create)
28
- parent = @document._parent
29
+ return document if validate && document.invalid?(:create)
30
+ parent = document._parent
29
31
  if parent.new_record?
30
32
  parent.insert
31
33
  else
32
- update = { @document._inserter => { @document._position => @document.raw_attributes } }
33
- @collection.update(parent._selector, update, @options.merge(:multi => false))
34
- @document.new_record = false
34
+ update = { document._inserter => { document._position => document.raw_attributes } }
35
+ collection.update(parent._selector, update, options.merge(:multi => false))
36
+ document.new_record = false
35
37
  end
36
- @document
38
+ document
37
39
  end
38
40
  end
39
41
  end
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Persistence #:nodoc:
4
+
4
5
  # Remove is a persistence command responsible for deleting a document from
5
6
  # the database.
6
7
  #
@@ -11,6 +12,7 @@ module Mongoid #:nodoc:
11
12
  # false
12
13
  # );
13
14
  class Remove < Command
15
+
14
16
  # Remove the document from the database: delegates to the MongoDB
15
17
  # collection remove method.
16
18
  #
@@ -28,13 +30,13 @@ module Mongoid #:nodoc:
28
30
  protected
29
31
  # Remove the document from the database.
30
32
  def remove
31
- if @document.embedded?
33
+ if document.embedded?
32
34
  Persistence::RemoveEmbedded.new(
33
- @document,
34
- @options.merge(:validate => @validate)
35
+ document,
36
+ options.merge(:validate => validate)
35
37
  ).persist
36
38
  else
37
- @collection.remove({ :_id => @document.id }, @options)
39
+ collection.remove({ :_id => document.id }, options)
38
40
  end; true
39
41
  end
40
42
  end
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Persistence #:nodoc:
4
+
4
5
  # Remove is a persistence command responsible for deleting a document from
5
6
  # the database.
6
7
  #
@@ -11,6 +12,7 @@ module Mongoid #:nodoc:
11
12
  # false
12
13
  # );
13
14
  class RemoveAll < Command
15
+
14
16
  # Remove the document from the database: delegates to the MongoDB
15
17
  # collection remove method.
16
18
  #
@@ -28,10 +30,10 @@ module Mongoid #:nodoc:
28
30
  protected
29
31
  # Remove the document from the database.
30
32
  def remove
31
- selector = (@klass.hereditary? ? @selector.merge(:_type => @klass.name) : @selector)
32
- count = @collection.find(selector).count
33
- @collection.remove(selector, @options)
34
- count
33
+ select = (klass.hereditary? ? selector.merge(:_type => klass.name) : selector)
34
+ collection.find(select).count.tap do
35
+ collection.remove(select, options)
36
+ end
35
37
  end
36
38
  end
37
39
  end
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Persistence #:nodoc:
4
+
4
5
  # Remove is a persistence command responsible for deleting a document from
5
6
  # the database.
6
7
  #
@@ -11,6 +12,7 @@ module Mongoid #:nodoc:
11
12
  # false
12
13
  # );
13
14
  class RemoveEmbedded < Command
15
+
14
16
  # Remove the document from the database. If the parent is a new record,
15
17
  # it will get removed in Ruby only. If the parent is not a new record
16
18
  # then either an $unset or $set will occur, depending if it's an
@@ -24,22 +26,22 @@ module Mongoid #:nodoc:
24
26
  #
25
27
  # +true+ or +false+, depending on if the removal passed.
26
28
  def persist
27
- parent = @document._parent
28
- parent.remove(@document)
29
+ parent = document._parent
30
+ parent.remove_child(document)
29
31
  unless parent.new_record?
30
- update = { @document._remover => removal_selector }
31
- @collection.update(parent._selector, update, @options.merge(:multi => false))
32
+ update = { document._remover => removal_selector }
33
+ collection.update(parent._selector, update, options.merge(:multi => false))
32
34
  end; true
33
35
  end
34
36
 
35
37
  protected
36
38
  # Get the value to pass to the removal modifier.
37
39
  def setter
38
- @document._index ? @document.id : true
40
+ document._index ? document.id : true
39
41
  end
40
42
 
41
43
  def removal_selector
42
- @document._index ? { @document._pull => { "_id" => @document.id } } : { @document._path => setter }
44
+ document._index ? { document._pull => { "_id" => document.id } } : { document._path => setter }
43
45
  end
44
46
  end
45
47
  end
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  module Persistence #:nodoc:
4
+
4
5
  # Update is a persistence command responsible for taking a document that
5
6
  # has already been saved to the database and saving it, depending on
6
7
  # whether or not the document has been modified.
@@ -28,6 +29,7 @@ module Mongoid #:nodoc:
28
29
  # );
29
30
  #
30
31
  class Update < Command
32
+
31
33
  # Persist the document that is to be updated to the database. This will
32
34
  # only write changed fields via MongoDB's $set modifier operation.
33
35
  #
@@ -39,12 +41,12 @@ module Mongoid #:nodoc:
39
41
  #
40
42
  # +true+ or +false+, depending on validation.
41
43
  def persist
42
- return false if validate && @document.invalid?(:update)
43
- @document.run_callbacks(:save) do
44
- @document.run_callbacks(:update) do
44
+ return false if validate && document.invalid?(:update)
45
+ document.run_callbacks(:save) do
46
+ document.run_callbacks(:update) do
45
47
  if update
46
- @document.move_changes
47
- @document._children.each do |child|
48
+ document.move_changes
49
+ document._children.each do |child|
48
50
  child.move_changes
49
51
  child.new_record = false if child.new_record?
50
52
  end
@@ -58,14 +60,14 @@ module Mongoid #:nodoc:
58
60
  protected
59
61
  # Update the document in the database atomically.
60
62
  def update
61
- updates = @document._updates
63
+ updates = document._updates
62
64
  unless updates.empty?
63
65
  other_pushes = updates.delete(:other)
64
- @collection.update(@document._selector, updates, @options.merge(:multi => false))
65
- @collection.update(
66
- @document._selector,
66
+ collection.update(document._selector, updates, options.merge(:multi => false))
67
+ collection.update(
68
+ document._selector,
67
69
  { "$pushAll" => other_pushes },
68
- @options.merge(:multi => false)
70
+ options.merge(:multi => false)
69
71
  ) if other_pushes
70
72
  end; true
71
73
  end
@@ -26,7 +26,7 @@ module Rails #:nodoc:
26
26
  # config.mongoid.reconnect_time = 10
27
27
  # end
28
28
  # end
29
- config.mongoid = ::Mongoid::Config.instance
29
+ config.mongoid = ::Mongoid::Config
30
30
 
31
31
  # Initialize Mongoid. This will look for a mongoid.yml in the config
32
32
  # directory and configure mongoid appropriately.
@@ -78,7 +78,7 @@ module Rails #:nodoc:
78
78
  # environments.
79
79
  initializer "preload all application models" do |app|
80
80
  config.to_prepare do
81
- ::Rails::Mongoid.load_models(app)
81
+ ::Rails::Mongoid.load_models(app) unless $rails_rake_task
82
82
  end
83
83
  end
84
84
 
@@ -98,14 +98,16 @@ namespace :db do
98
98
  end
99
99
  end
100
100
 
101
+ def collection_names
102
+ @collection_names ||= get_mongoid_models.map{ |d| d.collection.name }.uniq
103
+ end
104
+
101
105
  desc "Convert string objectids in mongo database to ObjectID type"
102
106
  task :objectid_convert => :environment do
103
- documents = get_mongoid_models
104
- documents.each do |document|
105
- puts "Converting #{document.to_s} to use ObjectIDs"
107
+ collection_names.each do |collection_name|
108
+ puts "Converting #{collection_name} to use ObjectIDs"
106
109
 
107
110
  # get old collection
108
- collection_name = document.collection.name
109
111
  collection = Mongoid.master.collection(collection_name)
110
112
 
111
113
  # get new collection (a clean one)
@@ -124,8 +126,7 @@ namespace :db do
124
126
  end
125
127
 
126
128
  # no errors. great! now rename _new to collection_name
127
- documents.each do |document|
128
- collection_name = document.collection.name
129
+ collection_names.each do |collection_name|
129
130
  collection = Mongoid.master.collection(collection_name)
130
131
  new_collection = collection.db["#{collection_name}_new"]
131
132
 
@@ -146,7 +147,7 @@ namespace :db do
146
147
  begin
147
148
  new_collection.rename(collection_name)
148
149
  rescue Exception => e
149
- puts "Unable to rename database #{new_collection.name} to #{collection_name}_old"
150
+ puts "Unable to rename database #{new_collection.name} to #{collection_name}"
150
151
  puts "reason: #{e.message}\n\n"
151
152
  end
152
153
  end
@@ -156,8 +157,8 @@ namespace :db do
156
157
 
157
158
  desc "Clean up old collections backed up by objectid_convert"
158
159
  task :cleanup_old_collections => :environment do
159
- get_mongoid_models.each do |document|
160
- collection = document.collection
160
+ collection_names.each do |collection_name|
161
+ collection = Mongoid.master.collection(collection_name)
161
162
  collection.db["#{collection.name}_old"].drop
162
163
  end
163
164
  end
@@ -0,0 +1,104 @@
1
+ # encoding: utf-8
2
+ require "mongoid/relations/accessors"
3
+ require "mongoid/relations/auto_save"
4
+ require "mongoid/relations/cascading"
5
+ require "mongoid/relations/cyclic"
6
+ require "mongoid/relations/proxy"
7
+ require "mongoid/relations/bindings"
8
+ require "mongoid/relations/builders"
9
+ require "mongoid/relations/many"
10
+ require "mongoid/relations/one"
11
+ require "mongoid/relations/polymorphic"
12
+ require "mongoid/relations/embedded/in"
13
+ require "mongoid/relations/embedded/many"
14
+ require "mongoid/relations/embedded/one"
15
+ require "mongoid/relations/referenced/in"
16
+ require "mongoid/relations/referenced/many"
17
+ require "mongoid/relations/referenced/many_to_many"
18
+ require "mongoid/relations/referenced/one"
19
+ require "mongoid/relations/reflections"
20
+ require "mongoid/relations/metadata"
21
+ require "mongoid/relations/macros"
22
+
23
+ module Mongoid # :nodoc:
24
+
25
+ # All classes and modules under the relations namespace handle the
26
+ # functionality that has to do with embedded and referenced (relational)
27
+ # associations.
28
+ module Relations
29
+ extend ActiveSupport::Concern
30
+ include Accessors
31
+ include AutoSave
32
+ include Cascading
33
+ include Cyclic
34
+ include Builders
35
+ include Macros
36
+ include Polymorphic
37
+ include Reflections
38
+
39
+ included do
40
+ attr_accessor :metadata
41
+ end
42
+
43
+ # Determine if the document itself is embedded in another document via the
44
+ # proper channels. (If it has a parent document.)
45
+ #
46
+ # @example Is the document embedded?
47
+ # address.embedded?
48
+ #
49
+ # @return [ true, false ] True if the document has a parent document.
50
+ #
51
+ # @since 2.0.0.rc.1
52
+ def embedded?
53
+ _parent.present?
54
+ end
55
+
56
+ # Determine if the document is part of an embeds_many relation.
57
+ #
58
+ # @example Is the document in an embeds many?
59
+ # address.embedded_many?
60
+ #
61
+ # @return [ true, false ] True if in an embeds many.
62
+ #
63
+ # @since 2.0.0.rc.1
64
+ def embedded_many?
65
+ metadata && metadata.macro == :embeds_many
66
+ end
67
+
68
+ # Determine if the document is part of an embeds_one relation.
69
+ #
70
+ # @example Is the document in an embeds one?
71
+ # address.embedded_one?
72
+ #
73
+ # @return [ true, false ] True if in an embeds one.
74
+ #
75
+ # @since 2.0.0.rc.1
76
+ def embedded_one?
77
+ metadata && metadata.macro == :embeds_one
78
+ end
79
+
80
+ # Determine if the document is part of an references_many relation.
81
+ #
82
+ # @example Is the document in a references many?
83
+ # post.referenced_many?
84
+ #
85
+ # @return [ true, false ] True if in a references many.
86
+ #
87
+ # @since 2.0.0.rc.1
88
+ def referenced_many?
89
+ metadata && metadata.macro == :references_many
90
+ end
91
+
92
+ # Determine if the document is part of an references_one relation.
93
+ #
94
+ # @example Is the document in a references one?
95
+ # address.referenced_one?
96
+ #
97
+ # @return [ true, false ] True if in a references one.
98
+ #
99
+ # @since 2.0.0.rc.1
100
+ def referenced_one?
101
+ metadata && metadata.macro == :references_one
102
+ end
103
+ end
104
+ end