Skip to content

Instantly share code, notes, and snippets.

@vzvu3k6k
Last active August 29, 2015 14:02
Show Gist options
  • Save vzvu3k6k/a8bb196b50b110dbe646 to your computer and use it in GitHub Desktop.
Save vzvu3k6k/a8bb196b50b110dbe646 to your computer and use it in GitHub Desktop.
# mode: ruby
# license: CC0
# Set the path of this file to BUNDLE_GEMFILE.
# Then Bundler will load Gemfile as usual,
# and next loads Gemfile.local only if it exists
# in the same directory as Gemfile.
#
# If Gemfile.local is loaded, lockfile is created
# as Gemfile.local.lock. Otherwise, lockfile is
# created as Gemfile.lock.
#
# Known problems:
# * Raises an error with git/github options
# "The git source git://... is not yet checked out. Please run `bundle install` before trying to start your application"
# (e.g. `gem 'asciidoctor-epub3', :github => 'opendevise/asciidoctor-epub3'`)
#
# Installation
# 1. Put this file on ~/.bundler/Gemfile (or somewhere)
# 2. `export BUNDLE_GEMFILE=~/.bundler/Gemfile`
#
# To disable it temporarily,
# $ env -u BUNDLE_GEMFILE bundle
def debug_print(msg)
warn(msg) if ENV['_BUNDLE_DEBUG']
end
debug_print "#{__FILE__} is loaded."
# Search `Gemfile`
bundle_gemfile = ENV['BUNDLE_GEMFILE']
ENV['BUNDLE_GEMFILE'] = nil
original_gemfile = SharedHelpers.send(:find_gemfile)
raise GemfileNotFound, "Could not locate Gemfile" unless original_gemfile
ENV['BUNDLE_GEMFILE'] = bundle_gemfile
# Eval `Gemfile`
eval_gemfile(original_gemfile)
debug_print "#{original_gemfile} is loaded."
# Search `Gemfile.local` in the same directory as `Gemfile`
local_gemfile = File.join(File.dirname(original_gemfile), "Gemfile.local")
# Eval `Gemfile.local` if possible
if File.readable?(local_gemfile)
default_gemfile = local_gemfile
eval_gemfile(local_gemfile)
debug_print "#{local_gemfile} is loaded."
else
default_gemfile = original_gemfile
end
# Override SharedHelpers.default_lockfile to create lockfile on the proper path
SharedHelpers.send(:define_method, :default_lockfile)do
Pathname.new("#{default_gemfile}.lock")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment