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.123.0 lib/eac_ruby_utils/envs/execution_result.rb
eac_ruby_utils-0.121.0 lib/eac_ruby_utils/envs/execution_result.rb
eac_ruby_utils-0.120.0 lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.76.1 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.76.0 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.75.2 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
eac_ruby_utils-0.119.2 lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.75.1 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.75.0 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
eac_ruby_utils-0.119.1 lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.74.1 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.74.0 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.73.0 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
eac_ruby_utils-0.119.0 lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.72.0 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
eac_ruby_utils-0.118.1 lib/eac_ruby_utils/envs/execution_result.rb
eac_ruby_utils-0.118.0 lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.70.1 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.70.0 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb
eac_tools-0.69.1 sub/eac_ruby_utils/lib/eac_ruby_utils/envs/execution_result.rb