0

所以我决定拆分我的上一篇文章,因为这个 bug 与 ByeBug 的关系比与 Pry-Remote 的关系更大(我认为)。最后发表网址:Pry-Remote 未触发 Rails 4

问题:

在 Pry-Remote 中键入 Next 时,ByeBug 会出现意外行为并进入“拆卸”状态。 在此处输入图像描述

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

我正在运行的内容:

  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

4

1 回答 1

1

您似乎使用的pry-byebug是. 如果您更新您的宝石,那么问题很可能会消失。3.2.01.3.3

更新

经过进一步研究,看起来 pry-remote 和 pry-byebug 在 Ruby 2.x 上不能很好地协同工作。

然而,有一个编码员发布了一些代码,大部分评论都是日文的,但他们声称这使得 pry-remote 工作。我在下面包括了他们的代码(我也翻译了日语):

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)

您需要调用这些方法,并且可能需要调整它们以供您使用。


参考

于 2015-10-12T15:49:45.673 回答