Class: Ripe::Blocks::BashBlock
- Inherits:
-
WorkingBlock
- Object
- Block
- WorkingBlock
- Ripe::Blocks::BashBlock
- Defined in:
- lib/ripe/blocks/bash_block.rb
Overview
This class represents a working block that should be processed using the Bash adaptor block. In ripe
<= 0.2.1, this templating system was the default behaviour of WorkingBlock.
Keys with string values in the format of:
vars["some_key"] = "value"
are converted as follows:
SOME_KEY="value"
Keys with array values in the format of:
vars["some_key"] = ["one", "two"]
are converted as follows:
SOME_KEY=("one" "two")
Instance Attribute Summary
Attributes inherited from Block
Class Method Summary collapse
-
.extension ⇒ String
Return expected file extension type for this type of ‘WorkingBlock`.
-
.id ⇒ String
Return string handle for referring to this type of ‘WorkingBlock`.
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 = {}) ⇒ BashBlock
constructor
Create a new, empty BashBlock.
Methods inherited from WorkingBlock
#prune, subclasses, #targets_exist?, #topology
Methods inherited from Block
#+, #prune, #targets_exist?, #topology, #|
Constructor Details
#initialize(filename, vars = {}) ⇒ BashBlock
Create a new, empty Ripe::Blocks::BashBlock.
38 39 40 |
# File 'lib/ripe/blocks/bash_block.rb', line 38 def initialize(filename, vars = {}) super(filename, vars) end |
Class Method Details
.extension ⇒ String
Return expected file extension type for this type of ‘WorkingBlock`.
99 100 101 |
# File 'lib/ripe/blocks/bash_block.rb', line 99 def self.extension 'sh' end |
.id ⇒ String
Return string handle for referring to this type of ‘WorkingBlock`.
88 89 90 |
# File 'lib/ripe/blocks/bash_block.rb', line 88 def self.id 'bash' 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::BashBlock was defined.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ripe/blocks/bash_block.rb', line 65 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.
48 49 50 51 52 53 54 |
# File 'lib/ripe/blocks/bash_block.rb', line 48 def declarations vars.map do |key, value| lh = key.upcase rh = value.is_a?(Array) ? "(\"#{value.join("\" \"")}\")" : "\"#{value}\"" "#{lh}=#{rh}" end end |