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.
Direct Known Subclasses
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.
-
#declarations ⇒ String
Return working block
parameters
as a sequence of bash variable assignments. -
#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.
20 21 22 23 |
# File 'lib/ripe/blocks/working_block.rb', line 20 def initialize(filename, vars = {}) @filename = filename super(File.basename(@filename), [], vars) end |
Instance Method Details
#command ⇒ String
Return the string command of the subtree starting at the current block.
The resulting string contains the result of the application of parameters to the task
from which the Ripe::Blocks::WorkingBlock was defined.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ripe/blocks/working_block.rb', line 48 def command <<-EOF.gsub(/^[ ]+/, '') # <#{id}> #{declarations.join("\n")} exec 1>"$LOG" 2>&1 #{File.new(@filename).read} echo "##.DONE.##" # </#{id}> EOF end |
#declarations ⇒ String
Return working block parameters
as a sequence of bash variable assignments.
31 32 33 34 35 36 37 |
# File 'lib/ripe/blocks/working_block.rb', line 31 def declarations vars.map do |key, value| lh = key.upcase rh = value.is_a?(Array) ? "(\"#{value.join("\" \"")}\")" : "\"#{value}\"" "#{lh}=#{rh}" end end |
#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
.
70 71 72 |
# File 'lib/ripe/blocks/working_block.rb', line 70 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
.
81 82 83 84 85 86 87 |
# File 'lib/ripe/blocks/working_block.rb', line 81 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.
95 96 97 |
# File 'lib/ripe/blocks/working_block.rb', line 95 def topology [@id] end |