Class: DataMapper::DescendantSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/dm-core/support/descendant_set.rb

Instance Method Summary collapse

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

Parameters:

  • descendants (#to_ary) (defaults to: [])

    initialize with the descendants



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

Parameters:

Returns:



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

Parameters:

Returns:



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

Yields:

  • (descendant)

Yield Parameters:

Returns:



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

Returns:

  • (Boolean)


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

Parameters:

Returns:

  • (undefined)


25
26
27
# File 'lib/dm-core/support/descendant_set.rb', line 25

def initialize_copy(original)
  @descendants = @descendants.dup
end