Class: Kumogata::PostProcessing
- Inherits:
-
Object
- Object
- Kumogata::PostProcessing
- Defined in:
- lib/kumogata/post_processing.rb
Constant Summary collapse
- TRIGGER_TIMING =
[:create, :update]
Instance Method Summary collapse
- #fetch!(template) ⇒ Object
-
#initialize(options) ⇒ PostProcessing
constructor
A new instance of PostProcessing.
- #run(timing, outputs) ⇒ Object
Constructor Details
#initialize(options) ⇒ PostProcessing
Returns a new instance of PostProcessing.
4 5 6 7 8 9 10 11 12 |
# File 'lib/kumogata/post_processing.rb', line 4 def initialize() @options = @commands = {} @command_options = { :undent => true, :trim_mode => nil, } end |
Instance Method Details
#fetch!(template) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/kumogata/post_processing.rb', line 14 def fetch!(template) _post = template.delete(:_post) return unless _post = _post[:options] || {} @command_options.merge() outputs = template['Outputs'] || {} _post.fetch(:commands).each do |name, attrs| unless attrs.kind_of?(Hash) and attrs['command'] raise "Invalid post processing: #{name} => #{attrs.inspect}" end timing = [(attrs['after'] || [:create])].flatten.map {|i| i.to_sym } command = attrs['command'] validate_timing(name, timing) validate_command_template(name, command, outputs) @commands[name] = { :after => timing, :command => command, } if (ssh = attrs['ssh']) validate_ssh(name, ssh, outputs) @commands[name][:ssh] = ssh end end end |
#run(timing, outputs) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/kumogata/post_processing.rb', line 46 def run(timing, outputs) results = [] @commands.each do |name, attrs| next unless attrs[:after].include?(timing) print_command(name) out, err, status = run_command(attrs, outputs) print_command_result(out, err, status) results << { name => { 'ExitStatus' => status.to_i, 'StdOut' => out.force_encoding('UTF-8'), 'StdErr' => err.force_encoding('UTF-8'), } } end if @options.command_result_log? and not results.empty? save_command_results(results) end end |