class Schmersion::AutoBundleExec

Attributes

argv[R]
bin[R]
gem_list[R]
gems[R]
pwd[R]

Public Class Methods

new(gems, pwd, bin, argv) click to toggle source
# File lib/schmersion/auto_bundle_exec.rb, line 25
def initialize(gems, pwd, bin, argv)
  @gems = gems
  @pwd = pwd
  @bin = bin
  @argv = argv
  check_dir
end
when_bundled(gems = [], pwd = Dir.pwd, bin = $PROGRAM_NAME, argv = ARGV) click to toggle source
# File lib/schmersion/auto_bundle_exec.rb, line 13
def self.when_bundled(gems = [], pwd = Dir.pwd, bin = $PROGRAM_NAME, argv = ARGV)
  return if ENV['BUNDLE_BIN_PATH']

  gems = Array(gems).compact
  return if gems.empty?

  instance = new(gems, pwd, bin, argv)
  return unless instance.bundled_dir?

  instance.re_exec if gems.all? { |gem| instance.bundled?(gem) }
end

Public Instance Methods

bundled?(gem) click to toggle source
# File lib/schmersion/auto_bundle_exec.rb, line 37
def bundled?(gem)
  gem_list.include?(" #{gem} ")
end
bundled_dir?() click to toggle source
# File lib/schmersion/auto_bundle_exec.rb, line 33
def bundled_dir?
  @is_bundled_dir
end
re_exec() click to toggle source
# File lib/schmersion/auto_bundle_exec.rb, line 41
def re_exec
  Kernel.exec(
    { 'SCHMERSION_DISABLE_AUTO_BUNDLE_EXEC' => '1' },
    'bundle', 'exec', bin, *argv
  )
end

Private Instance Methods

check_dir() click to toggle source
# File lib/schmersion/auto_bundle_exec.rb, line 52
def check_dir
  @gem_list, status = Open3.capture2e('bundle list')
  @is_bundled_dir = status.success?
end