Class: Ripe::Blocks::WorkingBlock
- 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.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Block
Class Method Summary collapse
-
.subclasses ⇒ Object
Collect a list of classes derived from ‘WorkingBlock`.
Instance Method Summary collapse
-
#initialize(filename, vars = {}) ⇒ WorkingBlock
constructor
Create a new, empty WorkingBlock.
-
#prune(protect, depend) ⇒ Block?
Prune the subtree starting at the current block.
-
#targets_exist? ⇒ Boolean
Test whether all targets for the current block exist.
-
#topology ⇒ Array<Symbol, Array>
Return the topology of the subtree starting at the current block in a nested list format.
Methods inherited from Block
Constructor Details
#initialize(filename, vars = {}) ⇒ WorkingBlock
Create a new, empty Ripe::Blocks::WorkingBlock.
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
.subclasses ⇒ Object
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.
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.
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 |
#topology ⇒ Array<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.
61 62 63 |
# File 'lib/ripe/blocks/working_block.rb', line 61 def topology [@id] end |