【问题标题】:Debugging a gem in ruby在 ruby​​ 中调试 gem
【发布时间】:2013-03-24 14:18:22
【问题描述】:

我有一个 gem,nanoc,我想调试它。

它的命令行 nanoc 执行以下脚本(在 /.rvm/gems/ruby-1.9.2-p290/bin 中)

#!/usr/bin/env ruby
#
# This file was generated by RubyGems.
#
# The application 'nanoc' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

version = ">= 0"

if ARGV.first
  str = ARGV.first
  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
  if str =~ /\A_(.*)_\z/
    version = $1
    ARGV.shift
  end
end

gem 'nanoc', version
load Gem.bin_path('nanoc', 'nanoc', version)

它本身在最后一行加载解析为 (/.rvm/gems/ruby-1.9.2-p290/gems/nanoc-3.6.2/bin)

#!/usr/bin/env ruby
# encoding: utf-8

# Try loading bundler if it's possible
begin
  require 'bundler/setup'
rescue LoadError
  # no problem
end

# Add lib to load path
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))

# Load nanoc
require 'nanoc'
require 'nanoc/cli'

# Run base
Nanoc::CLI.run(ARGV)

调试这类脚本的侵入性最小的选项是什么? 如果我只是撬第一个文件,ARGV 将是文件名本身..

我必须修改文件才能运行调试器吗?

【问题讨论】:

    标签: ruby debugging rubygems pry


    【解决方案1】:

    老实说,我不确定我是否理解这个问题。你可以把你的 pry 放在 nanoc 的库中。

    或者,您可以只 fork git repo,然后克隆它并使用它的包运行 gem 并以这种方式进行调试:

    https://github.com/nanoc/nanoc

    克隆存储库,添加调试代码,然后运行bundle exec bin/nanoc,这样您就可以保持本地安装的副本干净。一旦你找出问题所在,你就可以构建一个新的 gem,安装它,提交代码,然后提出一个 pull request 来为每个人修复它。

    【讨论】:

    • 我在库中的过滤器(一些 nanoc 概念)中有一个异常。我想知道如何轻松设置断点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-23
    • 2010-09-16
    相关资源
    最近更新 更多