mongoid 2.0.0.beta.20 → 2.0.0.rc.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 (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
@@ -4,8 +4,8 @@ module Mongoid #:nodoc:
4
4
  module Array #:nodoc:
5
5
  module Parentization #:nodoc:
6
6
  # Adds the parent document to each element in the array.
7
- def parentize(parent, association_name)
8
- each { |obj| obj.parentize(parent, association_name) }
7
+ def parentize(parent)
8
+ each { |obj| obj.parentize(parent) }
9
9
  end
10
10
  end
11
11
  end
@@ -5,7 +5,7 @@ module Mongoid #:nodoc:
5
5
  module Conversions #:nodoc:
6
6
  def get(value)
7
7
  return nil if value.blank?
8
- if Mongoid::Config.instance.use_utc?
8
+ if Mongoid::Config.use_utc?
9
9
  value.to_date
10
10
  else
11
11
  ::Date.new(value.year, value.month, value.day)
@@ -5,29 +5,6 @@ module Mongoid #:nodoc:
5
5
  module Conversions #:nodoc:
6
6
  extend ActiveSupport::Concern
7
7
 
8
- # Get the difference between 2 hashes. This will give back a new hash
9
- # with the keys and pairs of [ old, new ] values.
10
- #
11
- # Example:
12
- #
13
- # first = { :field => "value" }
14
- # second = { :field => "new" }
15
- # first.difference(second) # => { :field => [ "value", "new" ] }
16
- #
17
- # Returns:
18
- #
19
- # A +Hash+ of modifications.
20
- def difference(other)
21
- changes = {}
22
- each_pair do |key, value|
23
- if other.has_key?(key)
24
- new_value = other[key]
25
- changes[key] = [ value, new_value ] if new_value != value
26
- end
27
- end
28
- changes
29
- end
30
-
31
8
  module ClassMethods #:nodoc:
32
9
  def get(value)
33
10
  value
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+ module Mongoid #:nodoc:
3
+ module Extensions #:nodoc:
4
+ module Nil #:nodoc:
5
+ module Collectionization #:nodoc:
6
+ def collectionize
7
+ to_s.collectionize
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+ module Mongoid #:nodoc:
3
+ module Extensions #:nodoc:
4
+ module Object #:nodoc:
5
+ module Reflections #:nodoc:
6
+ extend ActiveSupport::Concern
7
+
8
+ def ivar(name)
9
+ if instance_variable_defined?("@#{name}")
10
+ return instance_variable_get("@#{name}")
11
+ end
12
+ nil
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+ module Mongoid #:nodoc:
3
+ module Extensions #:nodoc:
4
+ module Object #:nodoc:
5
+
6
+ # This module behaves like the master jedi.
7
+ module Yoda #:nodoc:
8
+
9
+ # Do or do not, there is no try. -- Yoda.
10
+ #
11
+ # @example Do or do not.
12
+ # object.do_or_do_not(:use, "The Force")
13
+ #
14
+ # @param [ String, Symbol ] name The method name.
15
+ # @param [ Array ] *args The arguments.
16
+ #
17
+ # @return [ Object, nil ] The result of the method call or nil if the
18
+ # method does not exist.
19
+ #
20
+ # @since 2.0.0.rc.1
21
+ def do_or_do_not(name, *args)
22
+ respond_to?(name) ? send(name, *args) : nil
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -3,11 +3,30 @@ module Mongoid #:nodoc:
3
3
  module Extensions #:nodoc:
4
4
  module String #:nodoc:
5
5
  module Conversions #:nodoc:
6
- def set(value)
7
- value.to_s unless value.nil?
6
+ extend ActiveSupport::Concern
7
+
8
+ # Convert the string to an array with the string in it.
9
+ #
10
+ # Example:
11
+ #
12
+ # <tt>"Testing".to_a</tt>
13
+ #
14
+ # Returns:
15
+ #
16
+ # An array with only the string in it.
17
+ def to_a
18
+ [ self ]
8
19
  end
9
- def get(value)
10
- value
20
+
21
+ module ClassMethods #:nodoc:
22
+
23
+ def get(value)
24
+ value
25
+ end
26
+
27
+ def set(value)
28
+ value.to_s unless value.nil?
29
+ end
11
30
  end
12
31
  end
13
32
  end
@@ -9,9 +9,9 @@ module Mongoid #:nodoc:
9
9
 
10
10
  def get(value)
11
11
  return nil if value.blank?
12
- value = value.getlocal unless Mongoid::Config.instance.use_utc?
13
- if Mongoid::Config.instance.use_activesupport_time_zone?
14
- time_zone = Mongoid::Config.instance.use_utc? ? 'UTC' : Time.zone
12
+ value = value.getlocal unless Mongoid::Config.use_utc?
13
+ if Mongoid::Config.use_activesupport_time_zone?
14
+ time_zone = Mongoid::Config.use_utc? ? 'UTC' : Time.zone
15
15
  value = value.in_time_zone(time_zone)
16
16
  end
17
17
  value
@@ -24,7 +24,7 @@ module Mongoid #:nodoc:
24
24
  end
25
25
 
26
26
  def convert_to_time(value)
27
- time = Mongoid::Config.instance.use_activesupport_time_zone? ? ::Time.zone : ::Time
27
+ time = Mongoid::Config.use_activesupport_time_zone? ? ::Time.zone : ::Time
28
28
  case value
29
29
  when ::String then time.parse(value)
30
30
  when ::DateTime then time.local(value.year, value.month, value.day, value.hour, value.min, value.sec)
@@ -1,16 +1,7 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc:
3
3
  class Field
4
- attr_reader :klass, :name, :type
5
-
6
- # Get the declared options for this field
7
- #
8
- # Returns:
9
- #
10
- # a hash of options
11
- def options
12
- @options
13
- end
4
+ attr_reader :copyable, :klass, :name, :options, :type
14
5
 
15
6
  # Get the default value for the field.
16
7
  #
@@ -34,25 +25,45 @@ module Mongoid #:nodoc:
34
25
  # <tt>Field.new(:score, :default => 0)</tt>
35
26
  def initialize(name, options = {})
36
27
  check_name!(name)
37
- @type = options[:type] || String
28
+ @type = options[:type] || Object
38
29
  @name, @default = name, options[:default]
39
30
  @copyable = (@default.is_a?(Array) || @default.is_a?(Hash))
40
31
  @options = options
41
32
  check_default!
42
33
  end
43
34
 
44
- # Used for setting an object in the attributes hash. If nil is provided the
45
- # default will get returned if it exists.
35
+ # Used for setting an object in the attributes hash.
36
+ #
37
+ # If nil is provided the default will get returned if it exists.
38
+ #
39
+ # If the field is an identity field, ie an id, it performs the necessary
40
+ # cast.
41
+ #
42
+ # Example:
43
+ #
44
+ # <tt>field.set("New Value")</tt>
45
+ #
46
+ # Returns:
47
+ #
48
+ # The new value.
46
49
  def set(object)
47
- unless @options[:identity]
50
+ unless options[:identity]
48
51
  type.set(object)
49
52
  else
50
- inverse = @options[:inverse_class_name].constantize
51
- object.blank? ? type.set(object) : BSON::ObjectId.cast!(inverse, object)
53
+ metadata = options[:metadata]
54
+ object.blank? ? type.set(object) : BSON::ObjectId.cast!(metadata.inverse_klass, object)
52
55
  end
53
56
  end
54
57
 
55
58
  # Used for retrieving the object out of the attributes hash.
59
+ #
60
+ # Example:
61
+ #
62
+ # <tt>field.get("Value")</tt>
63
+ #
64
+ # Returns:
65
+ #
66
+ # The converted value.
56
67
  def get(object)
57
68
  type.get(object)
58
69
  end
@@ -60,7 +71,7 @@ module Mongoid #:nodoc:
60
71
  protected
61
72
  # Slightly faster default check.
62
73
  def copy
63
- @copyable ? @default.dup : @default
74
+ copyable ? @default.dup : @default
64
75
  end
65
76
 
66
77
  # Check if the name is valid.
@@ -72,8 +83,8 @@ module Mongoid #:nodoc:
72
83
 
73
84
  def check_default!
74
85
  return if @default.is_a?(Proc)
75
- if !@default.nil? && !@default.is_a?(@type)
76
- raise Mongoid::Errors::InvalidType.new(@type, @default)
86
+ if !@default.nil? && !@default.is_a?(type)
87
+ raise Mongoid::Errors::InvalidType.new(type, @default)
77
88
  end
78
89
  end
79
90
  end
@@ -50,11 +50,21 @@ module Mongoid #:nodoc
50
50
 
51
51
  # Create the field accessors.
52
52
  def create_accessors(name, meth, options = {})
53
- define_method(meth) { read_attribute(name) }
54
- define_method("#{meth}=") { |value| write_attribute(name, value) }
55
- define_method("#{meth}?") do
56
- attr = read_attribute(name)
57
- (options[:type] == Boolean) ? attr == true : attr.present?
53
+ generated_field_methods.module_eval do
54
+ define_method(meth) { read_attribute(name) }
55
+ define_method("#{meth}=") { |value| write_attribute(name, value) }
56
+ define_method("#{meth}?") do
57
+ attr = read_attribute(name)
58
+ (options[:type] == Boolean) ? attr == true : attr.present?
59
+ end
60
+ end
61
+ end
62
+
63
+ def generated_field_methods
64
+ @generated_field_methods ||= begin
65
+ mod = Module.new
66
+ include mod
67
+ mod
58
68
  end
59
69
  end
60
70
  end
@@ -28,7 +28,7 @@ module Mongoid #:nodoc:
28
28
  #
29
29
  # <tt>Person.count(:conditions => { :attribute => "value" })</tt>
30
30
  def count(*args)
31
- Criteria.translate(self, *args).count
31
+ Criteria.translate(self, false, *args).count
32
32
  end
33
33
 
34
34
  # Returns true if there are on document in database based on the
@@ -36,7 +36,7 @@ module Mongoid #:nodoc:
36
36
  #
37
37
  # <tt>Person.exists?(:conditions => { :attribute => "value" })</tt>
38
38
  def exists?(*args)
39
- Criteria.translate(self, *args).limit(1).count == 1
39
+ Criteria.translate(self, false, *args).limit(1).count == 1
40
40
  end
41
41
 
42
42
  # Helper to initialize a new +Criteria+ object for this class, or return
@@ -45,8 +45,8 @@ module Mongoid #:nodoc:
45
45
  # Example:
46
46
  #
47
47
  # <tt>Person.criteria</tt>
48
- def criteria
49
- scope_stack.last || Criteria.new(self)
48
+ def criteria(embedded = false)
49
+ scope_stack.last || Criteria.new(self, embedded)
50
50
  end
51
51
 
52
52
  # Find a +Document+ in several different ways.
@@ -57,15 +57,24 @@ module Mongoid #:nodoc:
57
57
  # it will attempt to find either a single +Document+ or multiples based
58
58
  # on the conditions provided and the first parameter.
59
59
  #
60
- # <tt>Person.find(:first, :conditions => { :attribute => "value" })</tt>
60
+ # Example:
61
61
  #
62
+ # <tt>Person.find(:first, :conditions => { :attribute => "value" })</tt>
62
63
  # <tt>Person.find(:all, :conditions => { :attribute => "value" })</tt>
64
+ # <tt>Person.find(BSON::ObjectId)</tt>
65
+ #
66
+ # Options:
67
+ #
68
+ # args: An assortment of finder options.
63
69
  #
64
- # <tt>Person.find(Mongo::ObjectID.new.to_s)</tt>
70
+ # Returns:
71
+ #
72
+ # A document or criteria.
65
73
  def find(*args)
66
- raise Errors::InvalidOptions.new(:calling_document_find_with_nil_is_invalid, {}) if args[0].nil?
67
- type = args.delete_at(0) if args[0].is_a?(Symbol)
68
- criteria = Criteria.translate(self, *args)
74
+ raise Errors::InvalidOptions.new(
75
+ :calling_document_find_with_nil_is_invalid, {}
76
+ ) if args[0].nil?
77
+ type, criteria = Criteria.parse!(self, false, *args)
69
78
  case type
70
79
  when :first then return criteria.one
71
80
  when :last then return criteria.last
@@ -134,7 +143,7 @@ module Mongoid #:nodoc:
134
143
  #
135
144
  # Returns paginated array of docs.
136
145
  def paginate(params = {})
137
- Criteria.translate(self, params).paginate
146
+ Criteria.translate(self, false, params).paginate
138
147
  end
139
148
 
140
149
  protected
@@ -154,7 +163,6 @@ module Mongoid #:nodoc:
154
163
  def with_scope(criteria)
155
164
  scope_stack = self.scope_stack
156
165
  scope_stack << criteria
157
-
158
166
  begin
159
167
  yield criteria
160
168
  ensure
@@ -7,8 +7,13 @@ module Mongoid #:nodoc
7
7
  end
8
8
 
9
9
  module ClassMethods #:nodoc:
10
- # Returns <tt>true</tt> if the document inherits from another
11
- # Mongoid::Document.
10
+
11
+ # Determines if the document is a subclass of another document.
12
+ #
13
+ # @example Check if the document is a subclass.
14
+ # Square.hereditary?
15
+ #
16
+ # @return [ true, false ] True if hereditary, false if not.
12
17
  def hereditary?
13
18
  Mongoid::Document > superclass
14
19
  end
@@ -23,30 +28,29 @@ module Mongoid #:nodoc
23
28
  # always be preferred, since they are optimized calls... This operation
24
29
  # can get expensive in domains with large hierarchies.
25
30
  #
26
- # Example:
27
- #
28
- # <tt>person._children</tt>
31
+ # @example Get all the document's children.
32
+ # person._children
29
33
  #
30
- # Returns:
31
- #
32
- # All child +Documents+ to this +Document+ in the entire hierarchy.
34
+ # @return [ Array<Document> ] All child documents in the hierarchy.
33
35
  def _children
34
- associations.inject([]) do |children, (name, metadata)|
35
- if metadata.embedded? && name != "versions"
36
- child = send(name)
37
- child.to_a.each do |doc|
38
- children.push(doc).concat(doc._children)
39
- end unless child.blank?
36
+ relations.inject([]) do |children, (name, metadata)|
37
+ children.tap do |kids|
38
+ if metadata.embedded? && name != "versions"
39
+ child = send(name)
40
+ child.to_a.each do |doc|
41
+ kids.push(doc).concat(doc._children)
42
+ end unless child.blank?
43
+ end
40
44
  end
41
- children
42
45
  end
43
46
  end
44
47
 
45
- # Is inheritance in play here?
48
+ # Determines if the document is a subclass of another document.
46
49
  #
47
- # Returns:
50
+ # @example Check if the document is a subclass
51
+ # Square.new.hereditary?
48
52
  #
49
- # <tt>true</tt> if inheritance used, <tt>false</tt> if not.
53
+ # @return [ true, false ] True if hereditary, false if not.
50
54
  def hereditary?
51
55
  self.class.hereditary?
52
56
  end
@@ -54,21 +58,23 @@ module Mongoid #:nodoc
54
58
  # Sets up a child/parent association. This is used for newly created
55
59
  # objects so they can be properly added to the graph.
56
60
  #
57
- # Options:
58
- #
59
- # abject: The parent object that needs to be set for the child.
60
- # association_name: The name of the association for the child.
61
+ # @example Set the parent document.
62
+ # document.parentize(parent)
61
63
  #
62
- # Example:
64
+ # @param [ Document ] document The parent document.
63
65
  #
64
- # <tt>address.parentize(person, :addresses)</tt>
65
- def parentize(object, association_name)
66
- self._parent = object
67
- self.association_name = association_name.to_s
66
+ # @return [ Document ] The parent document.
67
+ def parentize(document)
68
+ self._parent = document
68
69
  end
69
70
 
70
- # Return the root +Document+ in the object graph. If the current +Document+
71
+ # Return the root document in the object graph. If the current document
71
72
  # is the root object in the graph it will return self.
73
+ #
74
+ # @example Get the root document in the hierarchy.
75
+ # document._root
76
+ #
77
+ # @return [ Document ] The root document in the hierarchy.
72
78
  def _root
73
79
  object = self
74
80
  while (object._parent) do object = object._parent; end