Sha256: 5f0f59c1ec95070b15d5a740dc0369f8692d81e050ad4e24acaba96a8e4d55f1

Contents?: true

Size: 1.42 KB

Versions: 6796

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

#
# {Pry::LastException} is a proxy class who wraps an Exception object for
# {Pry#last_exception}. it extends the exception object with methods that
# help pry commands be useful.
#
# the original exception object is not modified and method calls are forwarded
# to the wrapped exception object.
#
class Pry
  class LastException < BasicObject
    attr_accessor :bt_index

    def initialize(exception)
      @exception = exception
      @bt_index = 0
      @file, @line = bt_source_location_for(0)
    end

    def method_missing(name, *args, &block)
      if @exception.respond_to?(name)
        @exception.public_send(name, *args, &block)
      else
        super
      end
    end

    def respond_to_missing?(name, include_all = false)
      @exception.respond_to?(name, include_all)
    end

    #
    # @return [String]
    #  returns the path to a file for the current backtrace. see {#bt_index}.
    #
    attr_reader :file

    #
    # @return [Fixnum]
    #  returns the line for the current backtrace. see {#bt_index}.
    #
    attr_reader :line

    # @return [Exception]
    #   returns the wrapped exception
    #
    def wrapped_exception
      @exception
    end

    def bt_source_location_for(index)
      backtrace[index] =~ /(.*):(\d+)/
      [::Regexp.last_match(1), ::Regexp.last_match(2).to_i]
    end

    def inc_bt_index
      @bt_index = (@bt_index + 1) % backtrace.size
    end
  end
end

Version data entries

6,796 entries across 6,792 versions & 31 rubygems

Version Path
cybrid_api_bank_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/last_exception.rb
cybrid_api_id_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/last_exception.rb
cybrid_api_organization_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/last_exception.rb
cybrid_api_bank_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/last_exception.rb
cybrid_api_id_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/last_exception.rb
cybrid_api_organization_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/last_exception.rb
cybrid_api_bank_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/last_exception.rb
cybrid_api_organization_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/last_exception.rb
cybrid_api_id_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/last_exception.rb
ory-client-1.16.2 vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/last_exception.rb
avalara_sdk-24.12.2 vendor/bundle/ruby/2.7.0/gems/pry-0.13.1/lib/pry/last_exception.rb
cybrid_api_bank_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/last_exception.rb
cybrid_api_organization_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/last_exception.rb
cybrid_api_id_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/last_exception.rb
cybrid_api_bank_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/last_exception.rb
cybrid_api_id_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/last_exception.rb
cybrid_api_organization_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/last_exception.rb
ory-client-1.16.1 vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/last_exception.rb
ory-client-1.16.0 vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/last_exception.rb
cybrid_api_bank_ruby-0.123.143 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/last_exception.rb