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 = []) ⇒ 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

Parameters:

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

    initialize with the descendants



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

Parameters:

  • descendant (Module)

Returns:



33
34
35
36
# File 'lib/dm-core/support/descendant_set.rb', line 33

def <<(descendant)
  @descendants << descendant
  self
end

#clearDescendantSet

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

Returns:



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

Parameters:

  • descendant (Module)

Returns:



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

Yields:

  • (descendant)

Yield Parameters:

  • descendant (Module)

Returns:



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

Returns:

  • (Boolean)


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

Parameters:



21
22
23
# File 'lib/dm-core/support/descendant_set.rb', line 21

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