Class: Schmersion::AutoBundleExec

Inherits:
Object
  • Object
show all
Defined in:
lib/schmersion/auto_bundle_exec.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gems, pwd, bin, argv) ⇒ AutoBundleExec

Returns a new instance of AutoBundleExec.



25
26
27
28
29
30
31
# 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

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



11
12
13
# File 'lib/schmersion/auto_bundle_exec.rb', line 11

def argv
  @argv
end

#binObject (readonly)

Returns the value of attribute bin.



10
11
12
# File 'lib/schmersion/auto_bundle_exec.rb', line 10

def bin
  @bin
end

#gemsObject (readonly)

Returns the value of attribute gems.



8
9
10
# File 'lib/schmersion/auto_bundle_exec.rb', line 8

def gems
  @gems
end

#pwdObject (readonly)

Returns the value of attribute pwd.



9
10
11
# File 'lib/schmersion/auto_bundle_exec.rb', line 9

def pwd
  @pwd
end

Class Method Details

.when_bundled(gems = [], pwd = Dir.pwd, bin = $PROGRAM_NAME, argv = ARGV) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# 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

Instance Method Details

#bundled?(gem) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/schmersion/auto_bundle_exec.rb', line 37

def bundled?(gem)
  gem_list.include?(" #{gem} ")
end

#bundled_dir?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/schmersion/auto_bundle_exec.rb', line 33

def bundled_dir?
  @is_bundled_dir
end

#re_execObject



41
42
43
44
45
46
# 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