pry-debundle 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/LICENSE.MIT +19 -0
  2. data/README.md +87 -0
  3. data/lib/pry-debundle.rb +88 -0
  4. metadata +61 -0
data/LICENSE.MIT ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2012 Conrad Irwin <conrad.irwin@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,87 @@
1
+ `pry-debundle` allows you to require gems that are not in your `Gemfile` when inspecting
2
+ programs that are run with Bundler.
3
+
4
+ Usage
5
+ =====
6
+
7
+ 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.
8
+
9
+
10
+ Installation
11
+ ============
12
+
13
+ Add `pry` and `pry-debundle` to the Gemfile. These are both required, and have few (if
14
+ any) ill effects for developers who don't wish to use them.
15
+
16
+ ```ruby
17
+ group :development do
18
+ gem 'pry'
19
+ gem 'pry-debundle'
20
+ # other development gems everyone needs go here.
21
+ end
22
+ ```
23
+
24
+ If you need to install these gems without buy-in from the rest of your team (sad panda)
25
+ there are instructions under Personal Installation.
26
+
27
+
28
+ Long-winded Explanation
29
+ =======================
30
+
31
+ Bundler is an awesome gem that gives you a good degree of confidence that "if it works in
32
+ development, it works in production". It can do this by being vicious about gem
33
+ dependencies: if it's not in the `Gemfile`, it's not getting required. It also ensures
34
+ that everyone's development environment is identical, no more does "it works on my
35
+ machine" cut it as an excuse.
36
+
37
+ There are circumstances when this dogmatic dedication to duty can get in the way. In
38
+ particular all good developers have set up their development environment very personally.
39
+ Obviously, it's not important that my local tools work in production, and it's positively
40
+ bad for productivity if everyone is forced to have an identicial development setup.
41
+
42
+ So how do you reconcile these two points of view: "it should work the same everywhere",
43
+ and "it should be ideal for me"?
44
+
45
+ The obvious answer is to compromise; mostly "it should work the same everywhere", but when
46
+ I'm actively working on it (i.e. I have my `Pry` open) "it should be ideal for me".
47
+
48
+ To this end, `pry-debundle` will do nothing (I mean absolutely nothing) until you start
49
+ pry. At that point, the chains locking you into the Bundler jail are hacked asunder, and
50
+ immediately your precious pry plugins load, and all of those random gems you've
51
+ collected will be available to `require` as normal.
52
+
53
+ Before you rush off to try this, a word of warning: you will waste debugging time because
54
+ of this. Why? Because running a `require 'ampex'` inside Pry works, but running a `require
55
+ 'ampex'` outside Pry doesn't. "XOMGWTF? Ohhhh! GAH!!" I hear your future self cry as you
56
+ forget this warning, and then painfully recall it.
57
+
58
+ As the adage goes: "No gain, without pain".
59
+
60
+
61
+ Personal Installation
62
+ =====================
63
+
64
+ So let's say everyone on your team wants to use pry, but some of them are too scared to
65
+ use `pry-debundle`. This is pretty easy to support. Just add Pry to the Gemfile as
66
+ before, and then copy the implementation of the gem into your ~/.pryrc
67
+
68
+ ```ruby
69
+ group :development do
70
+ gem 'pry'
71
+ # other development gems everyone needs go here.
72
+ end
73
+ ```
74
+
75
+ ```bash
76
+ curl https://raw.github.com/ConradIrwin/pry-debundle/master/lib/pry-debundle.rb >> ~/.pryrc
77
+ ```
78
+
79
+ If you can't even persuade people to allow you to add Pry to the Gemfile, then you can
80
+ write a little wrapper script to run your app to make sure Pry is loaded before Bundler,
81
+ and install `pry-debundle` into your ~/.pryrc as above.
82
+
83
+ Meta-fu
84
+ =======
85
+
86
+ Licensed under the MIT license (see `LICENSE.MIT`). Bug reports and pull requests are
87
+ welcome.
@@ -0,0 +1,88 @@
1
+ # Copyright (c) Conrad Irwin <conrad.irwin@gmail.com> -- MIT License
2
+ # Source: https://github.com/ConradIrwin/pry-debundle
3
+ #
4
+ # To install and use this:
5
+ #
6
+ # 1. Recommended
7
+ # Add 'pry' to your Gemfile (in the development group)
8
+ # Add 'pry-debundle' to your Gemfile (in the development group)
9
+ #
10
+ # 2. OK, if colleagues are wary of pry-debundle:
11
+ # Add 'pry' to your Gemfile (in the development group)
12
+ # Copy this file into ~/.pryrc
13
+ #
14
+ # 3. Meh, if colleagues don't like Pry at all:
15
+ # Copy this file into ~/.pryrc
16
+ # Create a wrapper script that runs `pry -r<your-application>`
17
+ #
18
+ # 4. Pants, if you don't like Pry:
19
+ # Copy the definition of the debundle! method into your ~/.irbrc
20
+ # Call 'debundle!' from IRB when you need to.
21
+ #
22
+ class << Pry
23
+
24
+ # Break out of the Bundler jail.
25
+ #
26
+ # This can be used to load files in development that are not in your Gemfile (for
27
+ # example if you want to test something with a tool that you have locally).
28
+ #
29
+ # @example
30
+ # Pry.debundle!
31
+ # require 'all_the_things'
32
+ #
33
+ # Normally you don't need to cal this directly though, as it is called for you when Pry
34
+ # starts.
35
+ #
36
+ # See https://github.com/carlhuda/bundler/issues/183 for some background.
37
+ #
38
+ def debundle!
39
+ loaded = false
40
+
41
+ # Rubygems 1.8
42
+ if defined?(Gem.post_reset_hooks)
43
+ Gem.post_reset_hooks.reject!{ |hook| hook.source_location.first =~ %r{/bundler/} }
44
+ Gem::Specification.reset
45
+ load File.expand_path("../rubygems/custom_require.rb", Gem.method(:post_reset_hooks).source_location.first)
46
+ loaded = true
47
+
48
+ # Rubygems 1.6 — TODO might be quite slow.
49
+ elsif Gem.source_index && Gem.send(:class_variable_get, :@@source_index)
50
+ Gem.source_index.refresh!
51
+ load File.expand_path("../rubygems/custom_require.rb", Gem.method(:source_index).source_location.first)
52
+ loaded = true
53
+
54
+ else
55
+ raise "No hacks found :("
56
+ end
57
+ rescue => e
58
+ puts "Debundling failed: #{e.message}"
59
+ puts "When reporting bugs to https://github.com/ConradIrwin/pry-debundle, please include:"
60
+ puts "* gem version: #{Gem::VERSION rescue 'undefined'}"
61
+ puts "* bundler version: #{Bundler::VERSION rescue 'undefined'}"
62
+ puts "* pry version: #{Pry::VERSION rescue 'undefined'}"
63
+ puts "* ruby version: #{RUBY_VERSION rescue 'undefined'}"
64
+ puts "* ruby engine: #{RUBY_ENGINE rescue 'undefined'}"
65
+ else
66
+ load_additional_plugins if loaded
67
+ end
68
+
69
+ # After we've escaped from Bundler we want to look around and find any plugins the user
70
+ # has installed locally but not added to their Gemfile.
71
+ #
72
+ def load_additional_plugins
73
+ old_plugins = Pry.plugins.values
74
+ Pry.locate_plugins
75
+ new_plugins = Pry.plugins.values - old_plugins
76
+
77
+ new_plugins.each(&:activate!)
78
+ end
79
+ end
80
+
81
+ # Run just after a binding.pry, before you get dumped in the REPL.
82
+ # This handles the case where Bundler is loaded before Pry.
83
+ Pry.config.hooks.add_hook(:before_session, :debundle){ Pry.debundle! }
84
+
85
+ # Run after every line of code typed.
86
+ # This handles the case where you load something that loads bundler
87
+ # into your Pry.
88
+ Pry.config.hooks.add_hook(:after_eval, :debundle){ Pry.debundle! }
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pry-debundle
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Conrad Irwin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-07 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pry
16
+ requirement: &23738440 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *23738440
25
+ description: Hooks into Pry and removes the restrictions on loading gems imposed by
26
+ Bundler only when you're running in interactive mode.
27
+ email: conrad.irwin@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - lib/pry-debundle.rb
33
+ - README.md
34
+ - LICENSE.MIT
35
+ homepage: http://github.com/ConradIrwin/pry-debundle
36
+ licenses:
37
+ - MIT
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 1.8.17
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: Allows you to use gems not in your Gemfile from Pry.
60
+ test_files: []
61
+ has_rdoc: