lib/foreplay/engine/step.rb in foreplay-0.9.9 vs lib/foreplay/engine/step.rb in foreplay-0.9.10

- old
+ new

@@ -1,26 +1,34 @@ class Foreplay::Engine::Step - attr_reader :step, :instructions + include Foreplay + attr_reader :host, :step, :instructions - def initialize(s, i) + def initialize(h, s, i) + @host = h @step = s @instructions = i end - def build + def commands + return @commands if @commands + # Each step can be (1) a command or (2) a series of values to add to a file if step.key?('key') - instructions.key?(step['key']) ? commands : [] + if instructions.key?(step['key']) + build_commands + else + @commands = [] + end else # ...or just execute the command specified - [step['command']] + @commands = [command] end + + @commands end - def commands - return @commands if @commands - + def build_commands step['silent'] = true if header? @commands = ["echo \"#{header}\" > #{filename}"] redirect @@ -31,12 +39,10 @@ if instructions[key].is_a? Hash build_commands_from_hash else build_commands_from_string end - - @commands end def build_commands_from_hash instructions[key].each do |k, v| @commands << "echo \"#{before}#{k}#{delimiter}#{v}#{after}\" #{redirect} #{filename}" @@ -54,10 +60,14 @@ @redirect = true '>' end end + def command + @command ||= step['command'] + end + def filename @filename ||= "#{path}#{prefix}#{key}#{suffix}" end def key @@ -92,7 +102,16 @@ @header ||= step['header'] end def header? header.present? + end + + def silent + @silent ||= step['silent'] + end + + def announce + log "#{(step['commentary'] || command).yellow}", host: host, silent: silent + log command.cyan, host: host, silent: silent if instructions['verbose'] && step['commentary'] && command end end