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
parametersas a sequence of bash variable assignments. -
#initialize(filename, vars = {}) ⇒ WorkingBlock
constructor
A new instance of 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
Returns a new instance of WorkingBlock.
18 19 20 21 |
# File 'lib/ripe/blocks/working_block.rb', line 18 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.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ripe/blocks/working_block.rb', line 46 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.
29 30 31 32 33 34 35 |
# File 'lib/ripe/blocks/working_block.rb', line 29 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.
68 69 70 |
# File 'lib/ripe/blocks/working_block.rb', line 68 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.
79 80 81 82 83 84 85 |
# File 'lib/ripe/blocks/working_block.rb', line 79 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.
93 94 95 |
# File 'lib/ripe/blocks/working_block.rb', line 93 def topology [@id] end |