Sha256: 25a6635551c4a21484eb3b010f1a99c5979d7b059410e3b5e1cbe02a43c5313a

Contents?: true

Size: 821 Bytes

Versions: 1

Compression:

Stored size: 821 Bytes

Contents

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

module SilverSpurs
  class ChefRun

    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

1 entries across 1 versions & 1 rubygems

Version Path
silver_spurs-2.0.0.rc1 lib/silver_spurs/client/chef_run.rb