Class: DataMapper::Model::DescendantSet

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

Instance Method Summary collapse

Instance Method Details

#<<(model) ⇒ 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.

Append a model as a descendant

Parameters:

  • model (Model)

    the descendant model

Returns:



15
16
17
18
19
# File 'lib/dm-core/model/descendant_set.rb', line 15

def <<(model)
  @descendants << model unless @descendants.include?(model)
  @ancestors   << model if @ancestors
  self
end

#delete(model) ⇒ Model, NilClass

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 removed the descendant from the ancestors.

Parameters:

  • model (Model)

    the model to remove

Returns:

  • (Model, NilClass)

    the model is return if it is a descendant



48
49
50
51
# File 'lib/dm-core/model/descendant_set.rb', line 48

def delete(model)
  @ancestors.delete(model) if @ancestors
  @descendants.delete(model)
end

#each {|model| ... } ⇒ 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:

  • (model)

    iterate over each descendant

Yield Parameters:

  • model (Model)

    the descendant model

Returns:



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

def each
  @descendants.each { |model| yield model }
  self
end

#to_aryArray

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.

Return an Array representation of descendants

Returns:

  • (Array)

    the descendants



59
60
61
# File 'lib/dm-core/model/descendant_set.rb', line 59

def to_ary
  @descendants.dup
end