Module: CukeModeler::Containing

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

Overview

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

Instance Method Summary collapse

Instance Method Details

#each_descendant(&block) ⇒ Object

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



8
9
10
11
12
13
# File 'lib/cuke_modeler/containing.rb', line 8

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(&block) ⇒ Object

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



16
17
18
19
20
# File 'lib/cuke_modeler/containing.rb', line 16

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

  each_descendant(&block)
end