Class: Ripe::Blocks::SerialBlock
- Inherits:
-
MultiBlock
- Object
- Block
- MultiBlock
- Ripe::Blocks::SerialBlock
- Defined in:
- lib/ripe/blocks/serial_block.rb
Overview
This class represents a parallel composition of blocks, in that the children blocks of an instance of this class are to be run in serial.
Instance Attribute Summary
Attributes inherited from Block
Instance Method Summary collapse
-
#command ⇒ String
Return the string command of the subtree starting at the current block.
-
#initialize(*blocks) ⇒ SerialBlock
constructor
Create a new, empty SerialBlock.
-
#prune(protect, depend) ⇒ Block?
Prune the subtree starting at the current block.
- #super_prune ⇒ Object
Methods inherited from MultiBlock
Methods inherited from Block
#+, #targets_exist?, #topology, #|
Constructor Details
#initialize(*blocks) ⇒ SerialBlock
Create a new, empty Ripe::Blocks::SerialBlock.
16 17 18 |
# File 'lib/ripe/blocks/serial_block.rb', line 16 def initialize(*blocks) super(:+, *blocks) end |
Instance Method Details
#command ⇒ String
Return the string command of the subtree starting at the current block.
23 24 25 |
# File 'lib/ripe/blocks/serial_block.rb', line 23 def command @blocks.map { |block| "(\n%s\n)" % block.command }.join(' ; ') end |
#prune(protect, depend) ⇒ Block?
Prune the subtree starting at the current block.
Unless the block is protected, attempt to prune all children blocks. If all blocks are pruned, return nothing. If a single block remains, return that block. If more than one block remains, return the current MultiBlock.
A Ripe::Blocks::SerialBlock differs from a MultiBlock or ParallelBlock in that there is a linear dependency for its children blocks as they are to be run in serial. If a given block must be run, then all subsequent blocks that depend on it must be run as well.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ripe/blocks/serial_block.rb', line 37 def prune(protect, depend) return super_prune(protect, depend) if !depend return self if protect @blocks = @blocks.map do |block| new_protect = !block.targets_exist? new_block = block.prune(protect, depend) protect = new_protect new_block end @blocks = @blocks.compact case @blocks.length when 0 nil when 1 @blocks.first else self end end |
#super_prune ⇒ Object
27 |
# File 'lib/ripe/blocks/serial_block.rb', line 27 alias :super_prune :prune |