Class: Ripe::Blocks::Block Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/ripe/blocks.rb,
lib/ripe/blocks/block.rb

Overview

This class is abstract.

This class represents the fundamental building block of ripe.

Direct Known Subclasses

MultiBlock, WorkingBlock

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, blocks = [], vars = {}) ⇒ Block

Create a new, empty Ripe::Blocks::Block.

Parameters:

  • id (String)

    a mandatory, but optionally unique identifier for the block

  • blocks (Array<Block>) (defaults to: [])

    list of children blocks

  • vars (Hash<Symbol, String>) (defaults to: {})

    key-value pairs



31
32
33
# File 'lib/ripe/blocks/block.rb', line 31

def initialize(id, blocks = [], vars = {})
  @id, @blocks, @vars = id, blocks, vars
end

Instance Attribute Details

#blocksArray<Block> (readonly)

list of children blocks

Returns:

  • (Array<Block>)

    the current value of blocks



17
18
19
# File 'lib/ripe/blocks/block.rb', line 17

def blocks
  @blocks
end

#idString (readonly)

a mandatory, but optionally unique identifier for the block

Returns:

  • (String)

    the current value of id



17
18
19
# File 'lib/ripe/blocks/block.rb', line 17

def id
  @id
end

#varsHash<Symbol, String>

key-value pairs

Returns:

  • (Hash<Symbol, String>)

    the current value of vars



17
18
19
# File 'lib/ripe/blocks/block.rb', line 17

def vars
  @vars
end

Instance Method Details

#+(block) ⇒ Block

Compose a new serial block from two blocks. This method provides syntactic sugar in the form:

Block1 + Block2 + Block3

Parameters:

  • block (Block)

    a block

Returns:

  • (Block)

    serial block composition of the current block with the block passed in the argument list



107
108
109
# File 'lib/ripe/blocks/block.rb', line 107

def +(block)
  SerialBlock.new(self, block)
end

#commandString

Return the string command of the subtree starting at the current block.

Returns:

  • (String)

    subtree command



40
41
42
# File 'lib/ripe/blocks/block.rb', line 40

def command
  ''
end

#prune(protect, depend) ⇒ Block?

Prune the subtree starting at the current block.

Parameters:

  • protect (Boolean)

    if the current block (and recursively, its children) should be protected from pruning – setting this parameter to true guarantees that the block will not be pruned

  • depend (Boolean)

    if the current block is unprotected because its parent (serially) needs to be executed

Returns:

  • (Block, nil)

    a Block representing the subtree that has not been pruned, and nil otherwise



55
56
57
# File 'lib/ripe/blocks/block.rb', line 55

def prune(protect, depend)
  self
end

#targets_exist?Boolean

Test whether all targets for the current block exist.

Returns:

  • (Boolean)

    whether all targets exist



64
65
66
67
68
# File 'lib/ripe/blocks/block.rb', line 64

def targets_exist?
  # {Block} is an abstract class.  By default, assume that no targets
  # exist.
  false
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.

Returns:

  • (Array<Symbol, Array>)

    topology nested list



79
80
81
# File 'lib/ripe/blocks/block.rb', line 79

def topology
  []
end

#|(block) ⇒ Block

Compose a new parallel block from two blocks. This method provides syntactic sugar in the form:

Block1 | Block2 | Block3

Parameters:

  • block (Block)

    a block

Returns:

  • (Block)

    parallel block composition of the current block with the block passed in the argument list



93
94
95
# File 'lib/ripe/blocks/block.rb', line 93

def |(block)
  ParallelBlock.new(self, block)
end