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
13 14 15 |
# File 'lib/dm-core/support/descendant_set.rb', line 13 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
35 36 37 38 |
# File 'lib/dm-core/support/descendant_set.rb', line 35 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
86 87 88 |
# File 'lib/dm-core/support/descendant_set.rb', line 86 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
50 51 52 53 |
# File 'lib/dm-core/support/descendant_set.rb', line 50 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
64 65 66 67 68 69 70 |
# File 'lib/dm-core/support/descendant_set.rb', line 64 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
77 78 79 |
# File 'lib/dm-core/support/descendant_set.rb', line 77 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
23 24 25 |
# File 'lib/dm-core/support/descendant_set.rb', line 23 def initialize_copy(original) @descendants = @descendants.dup end |