Module: CukeModeler::Containing Private

Includes:
Enumerable
Included in:
Model
Defined in:
lib/cuke_modeler/containing.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

A mix-in module containing methods used by models that contain other models. Internal helper class.

Instance Method Summary collapse

Instance Method Details

#each {|The| ... } ⇒ Enumerable

Executes the given code block with this model and every model that is a child of this model. Exact order of model tree traversal is not guaranteed beyond the first model traversed, which will be the model that called this method. If no block is provided, an ‘Enumerator` is returned instead.

Examples:

model.each
model.each { |model| puts model.inspect }

Yield Parameters:

  • The (Model)

    current model being visited

Returns:

  • (Enumerable)

    if no block is given



24
25
26
27
28
29
30
31
# File 'lib/cuke_modeler/containing.rb', line 24

def each(&block)
  if block
    block.call(self)
    children.each { |child| child.each(&block) }
  else
    to_enum(:each)
  end
end

#each_descendant {|The| ... } ⇒ Object

Deprecated.

Use ‘Enumerable` module methods instead

Executes the given code block with every model that is a child of this model.

Examples:

model.each_descendant { |model| puts model.inspect }

Yield Parameters:

  • The (Model)

    current model being visited



42
43
44
45
46
47
# File 'lib/cuke_modeler/containing.rb', line 42

def each_descendant(&block)
  children.each do |child_model|
    block.call(child_model)
    child_model.each_descendant(&block) if child_model.respond_to?(:each_descendant)
  end
end

#each_model {|The| ... } ⇒ Object

Deprecated.

Use ‘Enumerable` module methods instead

Executes the given code block with this model and every model that is a child of this model.

Examples:

model.each_model { |model| puts model.inspect }

Yield Parameters:

  • The (Model)

    current model being visited



58
59
60
61
62
# File 'lib/cuke_modeler/containing.rb', line 58

def each_model(&block)
  block.call(self)

  each_descendant(&block)
end