Sha256: 874a86511ea75a3d0eba0119eeab917fc0f7eaa62012cddd3622e15bd2b93246

Contents?: true

Size: 998 Bytes

Versions: 3

Compression:

Stored size: 998 Bytes

Contents

# frozen_string_literal: true

module RubyJard
  module Commands
    # Command used to explore stacktrace.
    class FrameCommand < Pry::ClassCommand
      group 'RubyJard'
      description 'Explore to any frame of current stacktrace.'

      match 'frame'

      banner <<-BANNER
      Usage: frame [FRAME_ID]

      Explore to any frame of current stacktrace.

      Examples:
        frame 4 # Jump to frame 4 in the backtrace
      BANNER

      def process
        frame = args.first
        raise Pry::CommandError, 'Frame ID is required' if frame.nil?
        raise Pry::CommandError, 'Frame ID must be numeric' unless frame =~ /^\d+$/i

        frame = frame.to_i
        if frame >= RubyJard.current_session.backtrace.length || frame < 0
          raise Pry::CommandError, "Frame #{frame} does not exist!"
        else
          RubyJard::ControlFlow.dispatch(:frame, frame: args.first)
        end
      end
    end
  end
end

Pry::Commands.add_command(RubyJard::Commands::FrameCommand)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby_jard-0.2.2 lib/ruby_jard/commands/frame_command.rb
ruby_jard-0.2.1 lib/ruby_jard/commands/frame_command.rb
ruby_jard-0.2.0 lib/ruby_jard/commands/frame_command.rb