Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Version 0.1

  • Loading branch information...
commit 9fd37191c2d03590c8e9ec518fc1a8639a397fd1 0 parents
@ConradIrwin authored
19 LICENSE.MIT
@@ -0,0 +1,19 @@
+Copyright (c) 2012 Conrad Irwin <conrad.irwin@gmail.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
87 README.md
@@ -0,0 +1,87 @@
+`pry-debundle` allows you to require gems that are not in your `Gemfile` when inspecting
+programs that are run with Bundler.
+
+Usage
+=====
+
+Use the `pry` command, or `binding.pry` as normal. Watch how you can require any gem, even if it's not in your `Gemfile` and celebrate! Avoid getting confused by that fact when trying to debug `'require'` statements.
+
+
+Installation
+============
+
+Add `pry` and `pry-debundle` to the Gemfile. These are both required, and have few (if
+any) ill effects for developers who don't wish to use them.
+
+```ruby
+group :development do
+ gem 'pry'
+ gem 'pry-debundle'
+ # other development gems everyone needs go here.
+end
+```
+
+If you need to install these gems without buy-in from the rest of your team (sad panda)
+there are instructions under Personal Installation.
+
+
+Long-winded Explanation
+=======================
+
+Bundler is an awesome gem that gives you a good degree of confidence that "if it works in
+development, it works in production". It can do this by being vicious about gem
+dependencies: if it's not in the `Gemfile`, it's not getting required. It also ensures
+that everyone's development environment is identical, no more does "it works on my
+machine" cut it as an excuse.
+
+There are circumstances when this dogmatic dedication to duty can get in the way. In
+particular all good developers have set up their development environment very personally.
+Obviously, it's not important that my local tools work in production, and it's positively
+bad for productivity if everyone is forced to have an identicial development setup.
+
+So how do you reconcile these two points of view: "it should work the same everywhere",
+and "it should be ideal for me"?
+
+The obvious answer is to compromise; mostly "it should work the same everywhere", but when
+I'm actively working on it (i.e. I have my `Pry` open) "it should be ideal for me".
+
+To this end, `pry-debundle` will do nothing (I mean absolutely nothing) until you start
+pry. At that point, the chains locking you into the Bundler jail are hacked asunder, and
+immediately your precious pry plugins load, and all of those random gems you've
+collected will be available to `require` as normal.
+
+Before you rush off to try this, a word of warning: you will waste debugging time because
+of this. Why? Because running a `require 'ampex'` inside Pry works, but running a `require
+'ampex'` outside Pry doesn't. "XOMGWTF? Ohhhh! GAH!!" I hear your future self cry as you
+forget this warning, and then painfully recall it.
+
+As the adage goes: "No gain, without pain".
+
+
+Personal Installation
+=====================
+
+So let's say everyone on your team wants to use pry, but some of them are too scared to
+use `pry-debundle`. This is pretty easy to support. Just add Pry to the Gemfile as
+before, and then copy the implementation of the gem into your ~/.pryrc
+
+```ruby
+group :development do
+ gem 'pry'
+ # other development gems everyone needs go here.
+end
+```
+
+```bash
+curl https://raw.github.com/ConradIrwin/pry-debundle/master/lib/pry-debundle.rb >> ~/.pryrc
+```
+
+If you can't even persuade people to allow you to add Pry to the Gemfile, then you can
+write a little wrapper script to run your app to make sure Pry is loaded before Bundler,
+and install `pry-debundle` into your ~/.pryrc as above.
+
+Meta-fu
+=======
+
+Licensed under the MIT license (see `LICENSE.MIT`). Bug reports and pull requests are
+welcome.
88 lib/pry-debundle.rb
@@ -0,0 +1,88 @@
+# Copyright (c) Conrad Irwin <conrad.irwin@gmail.com> -- MIT License
+# Source: https://github.com/ConradIrwin/pry-debundle
+#
+# To install and use this:
+#
+# 1. Recommended
+# Add 'pry' to your Gemfile (in the development group)
+# Add 'pry-debundle' to your Gemfile (in the development group)
+#
+# 2. OK, if colleagues are wary of pry-debundle:
+# Add 'pry' to your Gemfile (in the development group)
+# Copy this file into ~/.pryrc
+#
+# 3. Meh, if colleagues don't like Pry at all:
+# Copy this file into ~/.pryrc
+# Create a wrapper script that runs `pry -r<your-application>`
+#
+# 4. Pants, if you don't like Pry:
+# Copy the definition of the debundle! method into your ~/.irbrc
+# Call 'debundle!' from IRB when you need to.
+#
+class << Pry
+
+ # Break out of the Bundler jail.
+ #
+ # This can be used to load files in development that are not in your Gemfile (for
+ # example if you want to test something with a tool that you have locally).
+ #
+ # @example
+ # Pry.debundle!
+ # require 'all_the_things'
+ #
+ # Normally you don't need to cal this directly though, as it is called for you when Pry
+ # starts.
+ #
+ # See https://github.com/carlhuda/bundler/issues/183 for some background.
+ #
+ def debundle!
+ loaded = false
+
+ # Rubygems 1.8
+ if defined?(Gem.post_reset_hooks)
+ Gem.post_reset_hooks.reject!{ |hook| hook.source_location.first =~ %r{/bundler/} }
+ Gem::Specification.reset
+ load File.expand_path("../rubygems/custom_require.rb", Gem.method(:post_reset_hooks).source_location.first)
+ loaded = true
+
+ # Rubygems 1.6 — TODO might be quite slow.
+ elsif Gem.source_index && Gem.send(:class_variable_get, :@@source_index)
+ Gem.source_index.refresh!
+ load File.expand_path("../rubygems/custom_require.rb", Gem.method(:source_index).source_location.first)
+ loaded = true
+
+ else
+ raise "No hacks found :("
+ end
+ rescue => e
+ puts "Debundling failed: #{e.message}"
+ puts "When reporting bugs to https://github.com/ConradIrwin/pry-debundle, please include:"
+ puts "* gem version: #{Gem::VERSION rescue 'undefined'}"
+ puts "* bundler version: #{Bundler::VERSION rescue 'undefined'}"
+ puts "* pry version: #{Pry::VERSION rescue 'undefined'}"
+ puts "* ruby version: #{RUBY_VERSION rescue 'undefined'}"
+ puts "* ruby engine: #{RUBY_ENGINE rescue 'undefined'}"
+ else
+ load_additional_plugins if loaded
+ end
+
+ # After we've escaped from Bundler we want to look around and find any plugins the user
+ # has installed locally but not added to their Gemfile.
+ #
+ def load_additional_plugins
+ old_plugins = Pry.plugins.values
+ Pry.locate_plugins
+ new_plugins = Pry.plugins.values - old_plugins
+
+ new_plugins.each(&:activate!)
+ end
+end
+
+# Run just after a binding.pry, before you get dumped in the REPL.
+# This handles the case where Bundler is loaded before Pry.
+Pry.config.hooks.add_hook(:before_session, :debundle){ Pry.debundle! }
+
+# Run after every line of code typed.
+# This handles the case where you load something that loads bundler
+# into your Pry.
+Pry.config.hooks.add_hook(:after_eval, :debundle){ Pry.debundle! }
14 pry-debundle.gemspec
@@ -0,0 +1,14 @@
+Gem::Specification.new do |s|
+ s.name = "pry-debundle"
+ s.version = "0.1"
+ s.platform = Gem::Platform::RUBY
+ s.author = "Conrad Irwin"
+ s.email = "conrad.irwin@gmail.com"
+ s.license = "MIT"
+ s.homepage = "http://github.com/ConradIrwin/pry-debundle"
+ s.summary = "Allows you to use gems not in your Gemfile from Pry."
+ s.description = "Hooks into Pry and removes the restrictions on loading gems imposed by Bundler only when you're running in interactive mode."
+ s.files = ["lib/pry-debundle.rb", "README.md", "LICENSE.MIT"]
+ s.require_path = "lib"
+ s.add_dependency 'pry'
+end
Please sign in to comment.
Something went wrong with that request. Please try again.