Sha256: 51769ca6ac7de2007bb103fc6b8848045846fc9ceb45f958f042bf5fb2484fbe

Contents?: true

Size: 936 Bytes

Versions: 1

Compression:

Stored size: 936 Bytes

Contents

# frozen_string_literal: true

require "tty-command"

module CobraCommander
  module Executor
    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

1 entries across 1 versions & 1 rubygems

Version Path
cobra_commander-0.12.0 lib/cobra_commander/executor/context.rb