Class: Ripe::Blocks::WorkingBlock

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

Overview

This class represents a CLI::TaskCLI that has been parametrized. In the block arborescence, WorkingBlocks are always leaf nodes and therefore contain scripts to be executed.

In order version of ripe (<= 0.2.1), WorkingBlock and BashBlock were considered the same entity.

See Also:

  • CLI::TaskCLI
  • WorkerController::Preparer#prepare
  • BashBlock

Direct Known Subclasses

BashBlock, ERBBlock, LiquidBlock

Instance Attribute Summary

Attributes inherited from Block

#blocks, #id, #vars

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Block

#+, #command, #|

Constructor Details

#initialize(filename, vars = {}) ⇒ WorkingBlock

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

Parameters:

  • filename (String)

    filename of the template file

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

    key-value pairs



25
26
27
28
# File 'lib/ripe/blocks/working_block.rb', line 25

def initialize(filename, vars = {})
  @filename = filename
  super(File.basename(@filename), [], vars)
end

Class Method Details

.subclassesObject

Collect a list of classes derived from ‘WorkingBlock`.



70
71
72
# File 'lib/ripe/blocks/working_block.rb', line 70

def self.subclasses
  ObjectSpace.each_object(Class).select { |klass| klass < self }
end

Instance Method Details

#prune(protect, depend) ⇒ Block?

Prune the subtree starting at the current block.

A Ripe::Blocks::WorkingBlock will be pruned if its targets exists, unless the protect parameter is set to true.

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



36
37
38
# File 'lib/ripe/blocks/working_block.rb', line 36

def prune(protect, depend)
  targets_exist? && !protect ? nil : self
end

#targets_exist?Boolean

Test whether all targets for the current block exist.

For Ripe::Blocks::WorkingBlocks, if there is so much as a single target – a block variable starting with output_) that does not exist, return false. Otherwise, return true.

Returns:

  • (Boolean)

    whether all targets exist



47
48
49
50
51
52
53
# File 'lib/ripe/blocks/working_block.rb', line 47

def targets_exist?
  statuses = @vars.select { |key, _| !key[/^output_/].nil? }.values.flatten
  targets_exist = statuses.map { |target| File.exists? target }.inject(:&)

  # If there are no targets at all, then assume that all targets exist
  targets_exist == nil ? true : targets_exist
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.

Since a Ripe::Blocks::WorkingBlock is always a leaf node in the tree, the subtree starting at the leaf node only contains the Ripe::Blocks::WorkingBlock.

Returns:

  • (Array<Symbol, Array>)

    topology nested list



61
62
63
# File 'lib/ripe/blocks/working_block.rb', line 61

def topology
  [@id]
end