问题描述
我试图调试Rails应用程序使用的gem。
我在本地克隆了Gem以进行浏览(也允许我执行诸如 git bisect
等等)
#Gemfile
gemactive_admin,路径:〜/ dev-forks / active_admin
然而,我经常坚持将Pry添加到Gemfile的某处以便能够使用它,或者调用需要pry
住在代码中,尽管我不想在那里。例如,我有时会忘记它,修正bug,然后用Gemfile中的Pry提交到项目中。
如果我不这样做,一个 LoadError
会出现,无法加载这个文件 - pry(LoadError)
。
我必须要管理员在不同的上下文(Rails项目,Gem,本地Ruby)和实际的gem(Gemfile,require,已安装)之间有点迷失。
如何在Rails的Gem中使用 binding.pry
,而不需要Gemfiles的干预?
乔恩从过去!如你所知,我几乎可以解答你的所有问题。
在这种情况下,你实际上描述了两个问题:(a)你不能当Pry不在Gemfile中时需要'pry'
,(b)如果你不需要 require $ c
Bundler的工作内容如康拉德·欧文: b
$ b
因此,在做Bundle为我们Ruby开发者所做的所有好事情时,它的设计带来了一个警告:bundle / Gemfile之外的内容(例如系统宝石)不再存在。 它是如何通过重新定义 require
进程并更改你的 PATH
,以便它只能看到包中的内容。
这意味着你不能在不污染Gemfile的情况下使用Pry,你说对不对?没那么快。康拉德·欧文是一个聪明的小饼干,他提出了一个解决方案,并制作了,这是一款暂时颠覆Bundler针对我们的要求所提供补丁的宝石。
因此,您只需要 require'pry-debundle'
然后,对吧?等一下。是的,Debundle可能不在Gemfile中。
猴子修复程序是复制 pry-debundle.rb
到〜/ debundle.rb
,然后 load
即。 (现在,您需要Pry加载才能运行该源文件,但您只能运行 debundle!
方法来达到目标位置,需要Pry并且四处搜索。需要一点monkeypatching,但我正在公关工作。)
I am trying to debug a gem that's used by a Rails app.
I cloned the Gem locally to go prying around (and also allows me to do nice things such as git bisect
, etc.)
# Gemfile
gem "active_admin", path: "~/dev-forks/active_admin"
However, I am often stuck with adding Pry to a Gemfile somewhere to be able to use it, or calling require "pry"
live in the code even though I don't want it in there. For example, I will sometimes forget about it, fix the bug, and then commit to the project with Pry in the Gemfile.
Should I not do that, a LoadError
will arise, cannot load such file -- pry (LoadError)
.
I have to admin I'm a bit lost between the different contexts (Rails project, Gem, local Ruby) and actual gems (Gemfile, require, installed).
How can I use binding.pry
in a Gem within Rails, without intervention of the Gemfiles?
Jon from the past! As you know, I have the answers to (almost) all your problems.
In this case, you're actually describing two problems: (a) you can't require 'pry'
when Pry is not in the Gemfile, (b) you can't use Pry if you don't require
it.
What Bundler does, as Conrad Irwin writes:
So in doing all the good things Bundler does for us Ruby developers, it comes by design with a caveat: "what's outside the bundle/Gemfile (eg system gems) doesn't exist anymore." How it does that is by redefining the require
process and changes your PATH
so that it only sees what's in the bundle.
That means you can't use Pry at all without polluting the Gemfile, you say, right? Not so fast. Conrad Irwin being the smart little cookie that he is, came up with a solution and made Pry Debundle, a gem that temporarily reverses the patches Bundler made to our require.
So all you have to do is just require 'pry-debundle'
then, right? Oh... wait. Yep, Debundle is probably not in the Gemfile.
The monkey fix is to hard copy the source of pry-debundle.rb
to ~/debundle.rb
, and then load
that. (For now, you'll need Pry loaded to run that source file, but you can run only the debundle!
method to get there, require Pry, and go prying around. A little monkeypatching is needed, but I'm working on a PR.)
这篇关于无需修改Gemfile或使用`require`即可在宝石中使用Pry的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!