Sha256: 2b076c92f8a680f6d5200b692f1f390955be40c6493bb6ada20c47283a833018

Contents?: true

Size: 937 Bytes

Versions: 74

Compression:

Stored size: 937 Bytes

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/envs/execution_error'

module EacRubyUtils
  module Envs
    class ExecutionResult
      attr_reader :r, :options

      def initialize(result, options)
        @r = result
        @options = options
      end

      def result
        return exit_code_zero_result if exit_code_zero?
        return expected_error_result if expected_error?

        raise ::EacRubyUtils::Envs::ExecutionError, 'Failed!'
      end

      def success?
        exit_code_zero? || expected_error?
      end

      private

      def exit_code_zero?
        r[:exit_code]&.zero?
      end

      def exit_code_zero_result
        r[options[:output] || :stdout]
      end

      def expected_error_result
        options[:exit_outputs][r[:exit_code]]
      end

      def expected_error?
        options[:exit_outputs].is_a?(Hash) && options[:exit_outputs].key?(r[:exit_code])
      end
    end
  end
end

Version data entries

74 entries across 74 versions & 2 rubygems

Version Path
eac_ruby_utils-0.117.1 lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.69.0 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.68.0 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.67.1 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
eac_ruby_utils-0.117.0 lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.67.0 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.66.0 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.65.1 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
eac_ruby_utils-0.116.0 lib/eac_ruby_utils/envs/execution_result.rb
eac_ruby_utils-0.115.0 lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.65.0 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
eac_ruby_utils-0.114.0 lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.64.0 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
eac_ruby_utils-0.113.0 lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.63.0 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.62.1 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.62.0 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.61.1 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.61.0 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.60.3 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb