Class: Appraisal::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/appraisal/command.rb

Overview

Executes commands with a clean environment

Constant Summary collapse

BUNDLER_ENV_VARS =
%w(RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, options = {}) ⇒ Command

Returns a new instance of Command


10
11
12
13
14
15
# File 'lib/appraisal/command.rb', line 10

def initialize(command, options = {})
  @gemfile = options[:gemfile]
  @env = options.fetch(:env, {})
  @command = command_starting_with_bundle(command)
  @original_env = {}
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command


8
9
10
# File 'lib/appraisal/command.rb', line 8

def command
  @command
end

#envObject (readonly)

Returns the value of attribute env


8
9
10
# File 'lib/appraisal/command.rb', line 8

def env
  @env
end

#gemfileObject (readonly)

Returns the value of attribute gemfile


8
9
10
# File 'lib/appraisal/command.rb', line 8

def gemfile
  @gemfile
end

#original_envObject (readonly)

Returns the value of attribute original_env


8
9
10
# File 'lib/appraisal/command.rb', line 8

def original_env
  @original_env
end

Instance Method Details

#runObject


17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/appraisal/command.rb', line 17

def run
  with_clean_env { ensure_bundler_is_available }
  announce

  with_clean_env do
    env.each_pair do |key, value|
      ENV[key] = value
    end

    unless Kernel.system(command_as_string)
      exit(1)
    end
  end
end