Sha256: 252dcc1048ccf378b4109bd138994794d75e211374b1711001789e18f15ad2e3

Contents?: true

Size: 1011 Bytes

Versions: 2

Compression:

Stored size: 1011 Bytes

Contents

# frozen_string_literal: true

require "tty-command"

module CobraCommander
  module Executor
    # Represents a component context to execute a command
    # @private
    class Context
      attr_reader :component, :command

      def initialize(component, command)
        @component = component
        @command = command
        @tty = TTY::Command.new(pty: true, printer: :null, stderr: :stdout)
      end

      def results
        @results ||= @component.root_paths.map do |path|
          isolate_bundle do
            @tty.run!(command, chdir: path)
          end
        end
      end

      def component_name
        component.name
      end

      def success?
        results.all?(&:success?)
      end

      def output
        results.join("\n")
      end

      private

      def isolate_bundle(&block)
        if Bundler.respond_to?(:with_unbundled_env)
          Bundler.with_unbundled_env(&block)
        else
          Bundler.with_clean_env(&block)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cobra_commander-0.14.0 lib/cobra_commander/executor/context.rb
cobra_commander-0.13.0 lib/cobra_commander/executor/context.rb