Sha256: 1917f53bfcac6c555eefd9ec1aec42cacf5666efbfd163aaa619edf44a522942

Contents?: true

Size: 1.35 KB

Versions: 9

Compression:

Stored size: 1.35 KB

Contents

require 'bundler'
module BundlerHelpers
  extend self
  def install_bundle(dir)
    Dir.chdir(dir) do
      command = "env RUBYOPT= BUNDLE_GEMFILE=Gemfile bundle install"
      system(command)
      $?.exitstatus
    end
  end

  def ensure_installed(dir)
    gemfile_lock = dir + "/Gemfile.lock"
    gemfile = dir + "/Gemfile"
    bundle_environment = dir + "/.bundle/environment.rb"
    case
    when File.exist?(gemfile_lock) && File.mtime(gemfile) > File.mtime(gemfile_lock)
      puts "Gemfile #{gemfile} has changed since it was locked. Re-locking..."
      FileUtils.rm(gemfile_lock)
      FileUtils.rm_rf(dir + "/.bundle")
    when ! File.exist?(bundle_environment)
      puts "Bundle #{gemfile} not installed.  Installing..."
    when File.mtime(bundle_environment) < File.mtime(gemfile_lock)
      puts "#{gemfile_lock} is newer than #{bundle_environment}.  Reinstalling"
    else
      return false
    end
    install_bundle(dir)
  end

  def expand_gemfile(gemfile)
    possibilities = [File.expand_path(gemfile, Dir.pwd), SporkWorld::GEMFILES_ROOT + gemfile + "Gemfile"]
    possibilities.detect {|f| File.exist?(f)} || raise(RuntimeError, %(Gemfile not found:\n #{possibilities * "\n"}))
  end

  def set_gemfile(gemfile)
    gemfile = expand_gemfile(gemfile || "rails3.0")
    ensure_installed(File.dirname(gemfile))
    ENV["BUNDLE_GEMFILE"] = gemfile
  end
end

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
spork-0.9.0.rc5 features/support/bundler_helpers.rb
spork-0.9.0.rc4 features/support/bundler_helpers.rb
spork-0.9.0.rc3 features/support/bundler_helpers.rb
nimboids-spork-0.8.99 features/support/bundler_helpers.rb
nimboids-spork-0.9.0.rc2 features/support/bundler_helpers.rb
invo-sporknife-0.1.0.1 features/support/bundler_helpers.rb
invo-sporknife-0.1.0 features/support/bundler_helpers.rb
invo-sporknife-0.1.0.pre features/support/bundler_helpers.rb
spork-0.9.0.rc2 features/support/bundler_helpers.rb