Sha256: 3c9a483220721decd51101ffab05f479fdee83910151702b69a0a8c89357f472

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

require 'pry'

module PryNav
  Commands = Pry::CommandSet.new do
    command 'step', 'Step execution into the next line or method.' do |steps|
      check_file_context
      breakout_navigation :step, steps
    end

    command 'next', 'Execute the next line within the same stack frame.' do |lines|
      check_file_context
      breakout_navigation :next, lines
    end

    command 'continue', 'Continue program execution and end the Pry session.' do
      check_file_context
      run 'exit-all'
    end

    alias_command 'n', 'next'
    alias_command 's', 'step'
    alias_command 'c', 'continue'

    helpers do
      def breakout_navigation(action, times)
        _pry_.binding_stack.clear     # Clear the binding stack.
        throw :breakout_nav, {        # Break out of the REPL loop and
          action: action,             #   signal the tracer.
          times:  times
        }
      end

      # Ensures that a command is executed in a local file context.
      def check_file_context
        unless PryNav.check_file_context(target)
          raise Pry::CommandError, 'Cannot find local context. Did you use `binding.pry`?'
        end
      end
    end
  end
end

Pry.commands.import PryNav::Commands

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pry-nav-0.0.4 lib/pry-nav/commands.rb