Class: DataMapper::DescendantSet
- Inherits:
-
Object
- Object
- DataMapper::DescendantSet
- Includes:
- Enumerable
- Defined in:
- lib/dm-core/support/descendant_set.rb
Instance Method Summary collapse
-
#<<(descendant) ⇒ DescendantSet
private
Add a descendant.
-
#clear ⇒ DescendantSet
private
Removes all entries and returns self.
-
#delete(descendant) ⇒ DescendantSet
private
Remove a descendant.
-
#each {|descendant| ... } ⇒ DescendantSet
private
Iterate over each descendant.
-
#empty? ⇒ Boolean
private
Test if there are any descendants.
-
#initialize(descendants = []) ⇒ DescendantSet
constructor
private
Initialize a DescendantSet instance.
-
#initialize_copy(original) ⇒ Object
private
Copy a DescendantSet instance.
Constructor Details
#initialize(descendants = []) ⇒ DescendantSet
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a DescendantSet instance
11 12 13 |
# File 'lib/dm-core/support/descendant_set.rb', line 11 def initialize(descendants = []) @descendants = SubjectSet.new(descendants) end |
Instance Method Details
#<<(descendant) ⇒ DescendantSet
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Add a descendant
33 34 35 36 |
# File 'lib/dm-core/support/descendant_set.rb', line 33 def <<(descendant) @descendants << descendant self end |
#clear ⇒ DescendantSet
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Removes all entries and returns self
84 85 86 |
# File 'lib/dm-core/support/descendant_set.rb', line 84 def clear @descendants.clear end |
#delete(descendant) ⇒ DescendantSet
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Remove a descendant
Also removes from all descendants
48 49 50 51 |
# File 'lib/dm-core/support/descendant_set.rb', line 48 def delete(descendant) @descendants.delete(descendant) each { |d| d.descendants.delete(descendant) } end |
#each {|descendant| ... } ⇒ DescendantSet
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Iterate over each descendant
62 63 64 65 66 67 68 |
# File 'lib/dm-core/support/descendant_set.rb', line 62 def each @descendants.each do |descendant| yield descendant descendant.descendants.each { |dd| yield dd } end self end |
#empty? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Test if there are any descendants
75 76 77 |
# File 'lib/dm-core/support/descendant_set.rb', line 75 def empty? @descendants.empty? end |
#initialize_copy(original) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Copy a DescendantSet instance
21 22 23 |
# File 'lib/dm-core/support/descendant_set.rb', line 21 def initialize_copy(original) @descendants = @descendants.dup end |