首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pry Remote / ByeBug接下来进入Teardown

Pry Remote / ByeBug接下来进入Teardown
EN

Stack Overflow用户
提问于 2015-10-01 08:51:28
回答 1查看 1.4K关注 0票数 0

所以我决定将我的最后一篇文章分开,因为这个bug更多的是与ByeBug有关,而不是撬-远程(我想)。最后发布网址:Pry-Remote not triggered Rails 4

问题:

在Pry中键入Next时,ByeBug会意外地执行操作,并进入"teardown“。

还创建了一个ByeBug问题:https://github.com/deivid-rodriguez/pry-byebug/issues/78

我所要做的是:

代码语言:javascript
复制
  gem 'pry-byebug', '=1.3.3'
  gem 'pry-stack_explorer'
  gem 'pry-rails'
  gem 'pry-remote'

pry (0.10.2)
  coderay (~> 1.1.0)
  method_source (~> 0.8.1)
  slop (~> 3.4)
pry-byebug (1.3.3)
  byebug (~> 2.7)
  pry (~> 0.10)
pry-rails (0.3.4)
  pry (>= 0.9.10)
pry-remote (0.1.8)
  pry (~> 0.9)
  slop (~> 3.0)
pry-stack_explorer (0.4.9.2)
  binding_of_caller (>= 0.7)
  pry (>= 0.9.11)

ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]
Rails 4.2.4

注1:

更新了所有与撬有关的宝石

https://gist.github.com/YOUConsulting/65cdcdc22d32780dde51

EN

回答 1

Stack Overflow用户

发布于 2015-10-12 15:49:45

您似乎使用的是一个古老版本的pry-byebug,本文编写的最新版本是3.2.0,但您使用的是1.3.3。如果你更新你的宝石,很有可能这个问题就会消失。

更新

经过进一步的研究,看起来在Ruby2.x上,pry和pry不能很好地协同工作。

然而,有一些代码的编码张贴,大部分评论是用日语,但他们声称它使撬-远程工作。下面是他们的代码(我也翻译了日语):

代码语言:javascript
复制
module ObjectUtils

  # remote parameter is the ip address, default port is 9876
  def pry!(remote=nil, port=9876)
    $LOAD_PATH.unshift "#{ENV['RUBY_PATH']}/debuger"
    require 'pry'
    return if __callee__ == :pry1 and !Pry.instance_variable_get(:@pry_is_start)

    Pry.instance_variable_set(:@pry_is_start, true)

    # if defined? Pry and defined? PryStackExplorer and Pry.config.hooks.hook_exists? :after_session, :delete_frame_manager
    #   Pry.config.hooks.delete_hook :when_started, :save_caller_bindings
    #   Pry.config.hooks.delete_hook :after_session, :delete_frame_manager
    # end
    if remote or ENV['USE_PRY_REMOTE']
      if defined? PryNav
        if defined? ActionDispatch # rails application.
          if Pry.initial_session?
            warn '[0m[33mloading pry remote ...[0m'
            binding.of_caller(1).remote_pry(remote, port)
          end
        else
          binding.of_caller(1).remote_pry(remote, port)
        end
      else
        require_remote_debugger
        binding.of_caller(1).remote_pry(remote, port)
        `notify-send -t 5000 -- "exiting pry remote ..."` if find_executable 'notify-send'
      end
    else
      # if these constants are defined then you're already in a debugger session
      if defined? PryByebug or defined? PryDebugger or defined? PryNav
        if defined? ActionDispatch # rails application.
          if Pry.initial_session?
            # When sending a new request, it will reset Pry.initial_sesssion? It is true.
            # This ensures that, in the same request the debugger will be activated once.
            # Only on the next request will it be reinitialized
            warn '[1m[33mloading debugger ...[0m'
            binding.of_caller(1).pry
          end
        else
          binding.of_caller(1).pry
        end
      else
        require_debugger
        binding.of_caller(1).pry
      end
    end
  end

  def require_debugger
    case RbConfig::CONFIG['ruby_version']
    when '2.0.0'...'3.0.0'
      require 'pry-byebug'
    when '1.9.0'...'2.0.0'
      require 'pry-debugger'
    end
    # to make sure the debugger is loaded
    warn '[1m[33mloading debugger ...[0m'
    require 'ap'; AwesomePrint.pry!
  rescue LoadError
    require 'pry-nav'
    warn '[1m[33mloading debugger ...[0m'
  end

  def require_remote_debugger
    require 'pry-remote'
    require 'pry-nav'
    warn '[0m[33mloading pry remote ...[0m'
    `notify-send -t 10000 -- "loading pry remote ..."` if system 'which notify-send &>/dev/null'
    require 'ap'; AwesomePrint.pry!
  end

end

Kernel.send(:include, ObjectUtils)
Object.send(:include, Kernel)

您需要调用这些方法,并且可能需要根据您的使用情况对它们进行调整。

参考文献

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32883285

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档