Module: Hobo::Bundler

Defined in:
lib/hobo/bundler.rb

Defined Under Namespace

Classes: GemUi

Class Method Summary collapse

Class Method Details

.install_missing_dependenciesObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/hobo/bundler.rb', line 14

def self.install_missing_dependencies
  require 'bundler'
  require 'bundler/ui'
  require 'bundler/cli'
  require 'bundler/cli/install'

  # Override Gem output handlers
  Gem::DefaultUserInteraction.ui = GemUi.new
  Gem.configuration.verbose = false

  # Reset bundler & trigger install task
  ::Bundler.definition true
  bundler_install = ::Bundler::CLI::Install.new({})

  begin
    bundler_install.run
    Kernel.exec('hobo', *$HOBO_ARGV)
  rescue Exception => exception
    puts
    puts "Failed to install dependencies. Hobo can not proceed."
    puts "Please see the error below:"
    puts
    raise
  end
end

.is_hobo_bundled?Boolean

Returns:

  • (Boolean)


67
68
69
70
71
72
73
74
75
76
# File 'lib/hobo/bundler.rb', line 67

def self.is_hobo_bundled?
  begin
    ::Bundler.root
    ::Bundler.definition.dependencies.select do |dep|
      dep.name == 'hobo-inviqa'
    end.length > 0
  rescue ::Bundler::GemfileNotFound
    false
  end
end

.isolateObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/hobo/bundler.rb', line 40

def self.isolate
  ::Bundler.with_clean_env do
    # Override gemfile for bundler to use
    ENV['BUNDLE_GEMFILE'] = File.expand_path('../../../Gemfile', __FILE__)

    # Ensure Bundler is not caching anything
    ::Bundler.instance_variable_set('@load', nil)
    ::Bundler.definition true

    # This is required as of 1.6.5 due to this commit:
    # https://github.com/bundler/bundler/commit/4870340132878c30d49a5d5fc27257e2abe46e7e
    ::Bundler.class_eval do
      @root = Pathname.new File.dirname(ENV['BUNDLE_GEMFILE'])
    end

    begin
      ::Bundler.setup(:default)
    rescue ::Bundler::GemNotFound => exception
      puts "Missing runtime dependencies: #{exception}"
      puts "Installing..."

      Hobo::Bundler.install_missing_dependencies
    end
    yield
  end
end