Class: LittleGhost::BundleInstaller

Inherits:
Object
  • Object
show all
Defined in:
lib/little_ghost/cli.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(stdout:, stderr:, executable: nil, process_runner: nil) ⇒ BundleInstaller

Returns a new instance of BundleInstaller.



10
11
12
13
14
15
# File 'lib/little_ghost/cli.rb', line 10

def initialize(stdout:, stderr:, executable: nil, process_runner: nil)
  @stdout = stdout
  @stderr = stderr
  @executable = executable || -> { Gem.bin_path("bundler", "bundle") }
  @process_runner = process_runner || method(:run_bundle)
end

Instance Method Details

#install(root) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/little_ghost/cli.rb', line 17

def install(root)
  executable = @executable.call
  environment = {"BUNDLE_GEMFILE" => File.join(root, "Gemfile")}
  if (bundle_path = ENV["BUNDLE_PATH"])
    environment["BUNDLE_PATH"] = Pathname.new(bundle_path).absolute? ? bundle_path : File.expand_path(bundle_path, root)
  end
  status = @process_runner.call(environment, executable, root)
  status.success?
rescue Gem::Exception, SystemCallError => error
  @stderr.puts("Could not run bundle install: #{error.message}")
  false
end