Class: Ripe::Blocks::MultiBlock Abstract

Inherits:
Block
  • Object
show all
Defined in:
lib/ripe/blocks/multi_block.rb

Overview

This class is abstract.

This class represents a block composition, that is, a placeholder block that joins multiple blocks together.

This class only exists to provide a superclass for ParallelBlock and SerialBlock.

Direct Known Subclasses

ParallelBlock, SerialBlock

Instance Attribute Summary

Attributes inherited from Block

#blocks, #id, #vars

Instance Method Summary collapse

Methods inherited from Block

#+, #command, #|

Constructor Details

#initialize(id, *blocks) ⇒ MultiBlock



24
25
26
27
# File 'lib/ripe/blocks/multi_block.rb', line 24

def initialize(id, *blocks)
  # Ignore nil objects
  super(id, blocks.compact, {})
end

Instance Method Details

#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 Ripe::Blocks::MultiBlock.



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ripe/blocks/multi_block.rb', line 37

def prune(protect, depend)
  if !protect
    @blocks = @blocks.map { |block| block.prune(protect, depend) }.compact
    case @blocks.length
    when 0; nil
    when 1; @blocks.first
    else;   self
    end
  else
    self
  end
end

#targets_exist?Boolean

Test whether all targets for the current block exist.

A Ripe::Blocks::MultiBlock‘s targets exist if the targets of all its # children exist.



56
57
58
# File 'lib/ripe/blocks/multi_block.rb', line 56

def targets_exist?
  @blocks.map(&:targets_exist?).inject(:&)
end

#topologyArray<Symbol, Array>

Return the topology of the subtree starting at the current block in a nested list format. The first element of any nested list is the identifier of the corresponding block in the subtree, and the subsequent elements are each a subtree corresponding to the children blocks of the current subtree.



63
64
65
# File 'lib/ripe/blocks/multi_block.rb', line 63

def topology
  [@id] + @blocks.map(&:topology)
end