Created
May 4, 2018 21:43
-
-
Save petekinnecom/4c39ae1dddc28556747a6cda58d5153b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # If you'd like to be able to require the pry gem even though it isn't in your Gemfile, | |
| # you can use this file. I suggest putting it at `~/pry.rb`, then instead of calling | |
| # `require 'pry'; binding.pry` you can call `require '~/pry'; binding.pry | |
| class BundlerBreakout | |
| def initialize(libname) | |
| @libname = libname | |
| end | |
| def load | |
| require @libname | |
| rescue LoadError | |
| $LOAD_PATH.unshift(*libs) | |
| require @libname | |
| end | |
| private | |
| def libs | |
| clean_env do | |
| out = <<~`SH` | |
| ruby <<RUBY | |
| pre = \\$LOAD_PATH.dup | |
| require '#{@libname}' | |
| puts \\$LOAD_PATH - pre | |
| RUBY | |
| SH | |
| out.split("\n") | |
| end | |
| end | |
| def clean_env(&block) | |
| if defined?(Bundler) | |
| Bundler.with_clean_env(&block) | |
| else | |
| block.call | |
| end | |
| end | |
| end | |
| BundlerBreakout.new('pry').load |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment