Class: DataMapper::DescendantSet
- Includes:
- Enumerable
- Defined in:
- lib/dm-core/support/descendant_set.rb
Instance Method Summary collapse
-
#<<(descendant) ⇒ DescendantSet
private
Add a descendant.
-
#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 = []) ⇒ undefined
constructor
private
Initialize a DescendantSet instance.
-
#initialize_copy(original) ⇒ undefined
private
Copy a DescendantSet instance.
Constructor Details
#initialize(descendants = []) ⇒ undefined
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 = descendants.to_ary 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
37 38 39 40 |
# File 'lib/dm-core/support/descendant_set.rb', line 37 def <<(descendant) @descendants << descendant self 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
52 53 54 55 |
# File 'lib/dm-core/support/descendant_set.rb', line 52 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
66 67 68 69 70 71 72 |
# File 'lib/dm-core/support/descendant_set.rb', line 66 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
79 80 81 |
# File 'lib/dm-core/support/descendant_set.rb', line 79 def empty? @descendants.empty? end |
#initialize_copy(original) ⇒ undefined
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
25 26 27 |
# File 'lib/dm-core/support/descendant_set.rb', line 25 def initialize_copy(original) @descendants = @descendants.dup end |