lib/foreplay/engine/step.rb in foreplay-0.11.1 vs lib/foreplay/engine/step.rb in foreplay-0.11.2

- old
+ new

@@ -6,66 +6,64 @@ def initialize(h, s, i) @host = h @step = s @instructions = i - - @commands = nil - @redirect = nil + @redirect = false end def commands return @commands if @commands + @commands = [] # Each step can be (1) a command or (2) a series of values to add to a file if step.key?('key') - if instructions.key?(step['key']) - build_commands - else - @commands = [] - end + build_commands if instructions.key?(step['key']) else # ...or just execute the command specified @commands = [command] end @commands end def build_commands step['silent'] = !instructions.key?('verbose') + instructions[key].is_a?(Hash) ? build_commands_from_hash : build_commands_from_string + end - if header? - @commands = ["echo \"#{header}\" > #{filename}"] - redirect - else - @commands = [] - end + def build_commands_from_hash + delimiter == ': ' ? build_commands_from_hash_to_yaml : build_commands_from_hash_to_env + end - if instructions[key].is_a? Hash - build_commands_from_hash - else - build_commands_from_string + def build_commands_from_hash_to_yaml + instructions_yaml.each_line do |l| + @commands << "echo \"#{l.remove_trailing_newline.escape_double_quotes}\" #{redirect} #{filename}" end end - def build_commands_from_hash + def instructions_hash + header? ? { header => instructions[key] } : instructions[key] + end + + def instructions_yaml + YAML.dump instructions_hash + end + + def build_commands_from_hash_to_env instructions[key].each do |k, v| @commands << "echo \"#{before}#{k}#{delimiter}#{v}#{after}\" #{redirect} #{filename}" end end def build_commands_from_string @commands << "echo \"#{before}#{delimiter}#{instructions[key]}#{after}\" #{redirect} #{filename}" end def redirect - if @redirect - '>>' - else - @redirect = true - '>' - end + arrow = @redirect ? '>>' : '>' + @redirect = true + arrow end def command @command ||= step['command'] end