debundle 0.9.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.MIT +19 -0
  3. data/README.md +92 -0
  4. data/debundle.gemspec +13 -0
  5. data/lib/debundle.rb +151 -0
  6. metadata +51 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 97544bb4cd260c59184b14849f692bc44d234ca4
4
+ data.tar.gz: 7d1beec1f5b2de7840f7e59118a1f82585a88c72
5
+ SHA512:
6
+ metadata.gz: a18f8799a6486596a6000f4adc11bb233af62a805170e2cbab015669921a34613f579cbe66ad35bba8b5cc7776b46d50bc6c287700f627a50e3919c2a057220c
7
+ data.tar.gz: 8c4e6532d473e8571b731be85888a0c49ec5e0867cef37bfd236b48416cc87e07e139d02a63b6bdcd283d071275be46b97c469204f43a187e47b67d21864f60e
@@ -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.
@@ -0,0 +1,92 @@
1
+ `debundle` allows you to require gems that are not in your `Gemfile`
2
+ when inspecting programs that are run with Bundler.
3
+
4
+ Usage
5
+ =====
6
+ Use the `pry` command, or `binding.pry` as normal. Watch how you can
7
+ require any gem, even if it's not in your `Gemfile` and celebrate! Avoid
8
+ getting confused by that fact when trying to debug `'require'`
9
+ statements.
10
+
11
+
12
+ Installation
13
+ ============
14
+
15
+ Add `pry` and `pry-debundle` to the Gemfile. These are both required, and have few (if
16
+ any) ill effects for developers who don't wish to use them.
17
+
18
+ ```ruby
19
+ group :development do
20
+ gem 'pry'
21
+ gem 'pry-debundle'
22
+ # other development gems everyone needs go here.
23
+ end
24
+ ```
25
+
26
+ If you need to install these gems without buy-in from the rest of your team (sad panda)
27
+ there are instructions under Personal Installation.
28
+
29
+
30
+ Long-winded Explanation
31
+ =======================
32
+
33
+ Bundler is an awesome gem that gives you a good degree of confidence that "if it works in
34
+ development, it works in production". It can do this by being vicious about gem
35
+ dependencies: if it's not in the `Gemfile`, it's not getting required. It also ensures
36
+ that everyone's development environment is identical, no more does "it works on my
37
+ machine" cut it as an excuse.
38
+
39
+ There are circumstances when this dogmatic dedication to duty can get in the way. In
40
+ particular all good developers have set up their development environment very personally.
41
+ Obviously, it's not important that my local tools work in production, and it's positively
42
+ bad for productivity if everyone is forced to have an identicial development setup.
43
+
44
+ So how do you reconcile these two points of view: "it should work the same everywhere",
45
+ and "it should be ideal for me"?
46
+
47
+ The obvious answer is to compromise; mostly "it should work the same everywhere", but when
48
+ I'm actively working on it (i.e. I have my `Pry` open) "it should be ideal for me".
49
+
50
+ To this end, `pry-debundle` will do nothing (I mean absolutely nothing) until you start
51
+ pry. At that point, the chains locking you into the Bundler jail are hacked asunder, and
52
+ immediately your precious pry plugins load, and all of those random gems you've
53
+ collected will be available to `require` as normal.
54
+
55
+ Before you rush off to try this, a word of warning: you will waste debugging time because
56
+ of this. Why? Because running a `require 'ampex'` inside Pry works, but running a `require
57
+ 'ampex'` outside Pry doesn't. "XOMGWTF? Ohhhh! GAH!!" I hear your future self cry as you
58
+ forget this warning, and then painfully recall it.
59
+
60
+ As the adage goes: "No gain, without pain".
61
+
62
+
63
+ Personal Installation
64
+ =====================
65
+
66
+ So let's say everyone on your team wants to use pry, but some of them are too scared to
67
+ use `pry-debundle`. This is pretty easy to support. Just add Pry to the Gemfile as
68
+ before, and then copy the implementation of the gem into your ~/.pryrc
69
+
70
+ ```ruby
71
+ group :development do
72
+ gem 'pry'
73
+ # other development gems everyone needs go here.
74
+ end
75
+ ```
76
+
77
+ ```bash
78
+ curl https://raw.github.com/ConradIrwin/pry-debundle/master/lib/pry-debundle.rb >> ~/.pryrc
79
+ ```
80
+
81
+ If you can't even persuade people to allow you to add Pry to the Gemfile, then you can
82
+ write a little wrapper script to run your app to make sure Pry is loaded before Bundler,
83
+ and install `pry-debundle` into your ~/.pryrc as above.
84
+
85
+ Meta-fu
86
+ =======
87
+ Licensed under the MIT license (see `LICENSE.MIT`). Bug reports and pull requests are
88
+ welcome.
89
+
90
+ It's possible that Bundler will solve this issue themselves, in which case I expect to
91
+ deprecate this gem. See https://github.com/carlhuda/bundler/issues/183 for some
92
+ discussion.
@@ -0,0 +1,13 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "debundle"
3
+ s.version = "0.9.0.alpha"
4
+ s.authors = ["Conrad Irwin", "Jonathan Allard"]
5
+ s.email = ["conrad.irwin@gmail.com", "jonathan@allard.io"]
6
+
7
+ s.license = "MIT"
8
+ s.homepage = "http://github.com/joallard/debundle"
9
+ s.summary = "Allows you to use gems not in your Gemfile"
10
+ s.description = "Removes the restrictions on loading gems imposed by Bundler only when you're running in interactive mode."
11
+ s.files = `git ls-files`.split("\n")
12
+ s.require_paths = ["lib"]
13
+ end
@@ -0,0 +1,151 @@
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
+ # Run `gem which pry-debundle` outside the Ruby console,
20
+ # and call `load '/path/to/pry-debundle.rb'; Pry.debundle!`
21
+ # when you need to.
22
+
23
+ module Debundle
24
+
25
+ # Break out of the Bundler jail.
26
+ #
27
+ # This can be used to load files in development that are not in your
28
+ # Gemfile (for example if you want to test something with a tool
29
+ # that you have locally).
30
+ #
31
+ # @example
32
+ # Pry.debundle!
33
+ # require 'all_the_things'
34
+ #
35
+ # Normally you don't need to cal this directly though, as it is
36
+ # called for you when Pry starts.
37
+ #
38
+ # See https://github.com/carlhuda/bundler/issues/183 for some
39
+ # background.
40
+ #
41
+ def debundle!
42
+ return unless defined?(Bundler)
43
+ loaded = false
44
+
45
+ if rubygems_18_or_better?
46
+ if Gem.post_reset_hooks.reject!{ |hook| hook.source_location.first =~ %r{/bundler/} }
47
+ Bundler.preserve_gem_path
48
+ Gem.clear_paths
49
+ Gem::Specification.reset
50
+ remove_bundler_monkeypatches
51
+ loaded = true
52
+ end
53
+
54
+ # Rubygems 1.6 — TODO might be quite slow.
55
+ elsif Gem.source_index && Gem.send(:class_variable_get, :@@source_index)
56
+ Gem.source_index.refresh!
57
+ remove_bundler_monkeypatches
58
+ loaded = true
59
+
60
+ else
61
+ raise "No hacks found :("
62
+ end
63
+ rescue => e
64
+ puts "Debundling failed: #{e.message}"
65
+ puts "When reporting bugs to https://github.com/ConradIrwin/pry-debundle, please include:"
66
+ puts "* gem version: #{Gem::VERSION rescue 'undefined'}"
67
+ puts "* bundler version: #{Bundler::VERSION rescue 'undefined'}"
68
+ puts "* ruby version: #{RUBY_VERSION rescue 'undefined'}"
69
+ puts "* ruby engine: #{RUBY_ENGINE rescue 'undefined'}"
70
+ else
71
+ return false unless loaded
72
+
73
+ require 'pry' unless Debundle.pry_present?
74
+
75
+ Debundle.add_hooks
76
+ Debundle.load_additional_plugins
77
+
78
+ true
79
+ end
80
+
81
+ class << self
82
+ def pry_present?
83
+ Pry.respond_to?(:config)
84
+ end
85
+
86
+ def add_hooks
87
+ return false if defined?(@@already_hooked)
88
+ @@already_hooked = true
89
+
90
+ # Run just after a binding.pry, before you get dumped in the
91
+ # REPL. This handles the case where Bundler is loaded before Pry.
92
+ # NOTE: This hook happens *before* :before_session
93
+ Pry.config.hooks.add_hook(:when_started, :debundle){ Pry.debundle! }
94
+
95
+ # Run after every line of code typed. This handles the case
96
+ # where you load something that loads bundler into your Pry.
97
+ Pry.config.hooks.add_hook(:after_eval, :debundle){ Pry.debundle! }
98
+ end
99
+
100
+ # After we've escaped from Bundler we want to look around and find
101
+ # any plugins the user has installed locally but not added to
102
+ # their Gemfile.
103
+ #
104
+ def load_additional_plugins
105
+ old_plugins = Pry.plugins.values
106
+ Pry.locate_plugins
107
+ new_plugins = Pry.plugins.values - old_plugins
108
+
109
+ new_plugins.each(&:activate!)
110
+ end
111
+ end
112
+
113
+ private
114
+
115
+ def rubygems_18_or_better?
116
+ defined?(Gem.post_reset_hooks)
117
+ end
118
+
119
+ def rubygems_20_or_better?
120
+ Gem::VERSION.to_i >= 2
121
+ end
122
+
123
+ # Ugh, this stuff is quite vile.
124
+ def remove_bundler_monkeypatches
125
+ if rubygems_20_or_better?
126
+ load 'rubygems/core_ext/kernel_require.rb'
127
+ else
128
+ load 'rubygems/custom_require.rb'
129
+ end
130
+
131
+ if rubygems_18_or_better?
132
+ Kernel.module_eval do
133
+ def gem(gem_name, *requirements) # :doc:
134
+ skip_list = (ENV['GEM_SKIP'] || "").split(/:/)
135
+ raise Gem::LoadError, "skipping #{gem_name}" if skip_list.include? gem_name
136
+ spec = Gem::Dependency.new(gem_name, *requirements).to_spec
137
+ spec.activate if spec
138
+ end
139
+ end
140
+ else
141
+ Kernel.module_eval do
142
+ def gem(gem_name, *requirements) # :doc:
143
+ skip_list = (ENV['GEM_SKIP'] || "").split(/:/)
144
+ raise Gem::LoadError, "skipping #{gem_name}" if skip_list.include? gem_name
145
+ Gem.activate(gem_name, *requirements)
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
151
+
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: debundle
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0.alpha
5
+ platform: ruby
6
+ authors:
7
+ - Conrad Irwin
8
+ - Jonathan Allard
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-01-06 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Removes the restrictions on loading gems imposed by Bundler only when
15
+ you're running in interactive mode.
16
+ email:
17
+ - conrad.irwin@gmail.com
18
+ - jonathan@allard.io
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - LICENSE.MIT
24
+ - README.md
25
+ - debundle.gemspec
26
+ - lib/debundle.rb
27
+ homepage: http://github.com/joallard/debundle
28
+ licenses:
29
+ - MIT
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">"
43
+ - !ruby/object:Gem::Version
44
+ version: 1.3.1
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 2.5.1
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: Allows you to use gems not in your Gemfile
51
+ test_files: []