Class: Ripe::Blocks::LiquidBlock

Inherits:
WorkingBlock show all
Defined in:
lib/ripe/blocks/liquid_block.rb

Overview

This class represents a working block that should be processed using the Liquid templating engine, rather than the simple bash engine defined in WorkingBlock.

See Also:

Instance Attribute Summary

Attributes inherited from Block

#blocks, #id, #vars

Instance Method Summary collapse

Methods inherited from WorkingBlock

#prune, #targets_exist?, #topology

Methods inherited from Block

#+, #prune, #targets_exist?, #topology, #|

Constructor Details

#initialize(filename, vars = {}) ⇒ LiquidBlock



20
21
22
# File 'lib/ripe/blocks/liquid_block.rb', line 20

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

Instance Method Details

#commandString

Return the string command of the subtree starting at the current block.

The resulting string contains the render result of the liquid template based on the parameters specified in vars.



39
40
41
42
# File 'lib/ripe/blocks/liquid_block.rb', line 39

def command
  template = Liquid::Template.parse(File.new(@filename).read)
  template.render(declarations)
end

#declarationsHash<Symbol, Object>

Return liquid block parameters as a Hash<Symbol, Object>.



29
30
31
# File 'lib/ripe/blocks/liquid_block.rb', line 29

def declarations
  @vars.inject({}) { |memo, (k, v)| memo[k.to_s] = v; memo }
end