Sha256: cfd8b9be4db6cbac5ba75374c8e51841f3405ea09db4c230cc574d007e9dbff4

Contents?: true

Size: 824 Bytes

Versions: 2

Compression:

Stored size: 824 Bytes

Contents

require 'rest-client'
require 'silver_spurs/client/exceptions'
require 'erb'

module SilverSpurs
  class ChefOutput

    attr_reader :log, :status

    def initialize(response)
      @status = convert_status response
      @log = prettify_log response
    end

    private

    def convert_status(response)
      code = response[0]
      case code
      when 'ok'
        :success
      when 'error'
        :failed
      end
    end

    def prettify_log(response)
      run_info = response[1]
      stdout = run_info['stdout']
      stderr = run_info['stderr']
      exit_code = run_info['exit_code'] || run_info['exit_status']

      template = ERB.new <<-END
Exit Code: <%= exit_code %>
--STDOUT-----------------
<%= stdout %>
--STDERR-----------------
<%= stderr %>
END
      template.result binding
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
silver_spurs-2.0.0.rc5 lib/silver_spurs/client/chef_output.rb
silver_spurs-2.0.0.rc3 lib/silver_spurs/client/chef_output.rb