Class: Ripe::Blocks::BashBlock

Inherits:
WorkingBlock show all
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")

See Also:

Instance Attribute Summary

Attributes inherited from Block

#blocks, #id, #vars

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • filename (String)

    filename of the template file

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

    key-value pairs



38
39
40
# File 'lib/ripe/blocks/bash_block.rb', line 38

def initialize(filename, vars = {})
  super(filename, vars)
end

Class Method Details

.extensionString

Return expected file extension type for this type of ‘WorkingBlock`.

Returns:

  • (String)

See Also:



99
100
101
# File 'lib/ripe/blocks/bash_block.rb', line 99

def self.extension
  'sh'
end

.idString

Return string handle for referring to this type of ‘WorkingBlock`.

Returns:

  • (String)

See Also:



88
89
90
# File 'lib/ripe/blocks/bash_block.rb', line 88

def self.id
  'bash'
end

Instance Method Details

#commandString

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.

Returns:

  • (String)

    subtree command

See Also:



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

#declarationsString

Return working block parameters as a sequence of bash variable assignments.

Returns:

  • (String)

    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