Sha256: a039e5c78a8fd767823739fdcde5607c9c9e8042325f3d6234e48b3c99063193

Contents?: true

Size: 1.42 KB

Versions: 74

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/envs/execution_error'
require 'eac_ruby_utils/envs/execution_result'
require 'eac_ruby_utils/envs/process'
require 'eac_ruby_utils/envs/spawn'
require 'pp'

module EacRubyUtils
  module Envs
    module BaseCommand
      module Execution
        def execute!(options = {})
          options[:exit_outputs] = status_results.merge(options[:exit_outputs].presence || {})
          er = ::EacRubyUtils::Envs::ExecutionResult.new(execute(options), options)
          return er.result if er.success?

          raise ::EacRubyUtils::Envs::ExecutionError,
                "execute! command failed: #{self}\n#{er.r.pretty_inspect}"
        end

        def execute(options = {})
          c = command(options)
          debug_print("BEFORE: #{c}")
          t1 = Time.now
          r = ::EacRubyUtils::Envs::Process.new(c).to_h
          i = Time.now - t1
          debug_print("AFTER [#{i}]: #{c}")
          r
        end

        def spawn(options = {})
          c = command(options)
          debug_print("SPAWN: #{c}")
          ::EacRubyUtils::Envs::Spawn.new(c)
        end

        def system!(options = {})
          return if system(options)

          raise ::EacRubyUtils::Envs::ExecutionError, "system! command failed: #{self}"
        end

        def system(options = {})
          c = command(options)
          debug_print(c)
          Kernel.system(c)
        end
      end
    end
  end
end

Version data entries

74 entries across 74 versions & 2 rubygems

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