Sha256: 31b6129402d65b0633976ebb1e9d5309d9c9bc77ff2e2ed6f30c9baaf5cf2864

Contents?: true

Size: 1.42 KB

Versions: 6905

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

class Pry
  class Command
    class Edit
      module FileAndLineLocator
        class << self
          def from_binding(target)
            if target.respond_to?(:source_location)
              target.source_location
            else
              target.eval("[__FILE__, __LINE__]")
            end
          end

          def from_code_object(code_object, filename_argument)
            unless File.exist?(code_object.source_file.to_s)
              raise CommandError, "Cannot find a file for #{filename_argument}!"
            end

            [code_object.source_file, code_object.source_line]
          end

          def from_exception(exception, backtrace_level)
            raise CommandError, "No exception found." if exception.nil?

            file_name, line = exception.bt_source_location_for(backtrace_level)
            raise CommandError, "Exception has no associated file." if file_name.nil?

            if Pry.eval_path == file_name
              raise CommandError, "Cannot edit exceptions raised in REPL."
            end

            [file_name, line]
          end

          # when file and line are passed as a single arg, e.g my_file.rb:30
          def from_filename_argument(filename_argument)
            f = File.expand_path(filename_argument)
            l = f.sub!(/:(\d+)$/, "") ? Regexp.last_match(1).to_i : 1
            [f, l]
          end
        end
      end
    end
  end
end

Version data entries

6,905 entries across 6,900 versions & 33 rubygems

Version Path
ory-client-0.0.1.alpha37 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/edit/file_and_line_locator.rb
ory-client-0.0.1.alpha36 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/edit/file_and_line_locator.rb
ory-kratos-client-0.8.2.alpha1 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/edit/file_and_line_locator.rb
ory-client-0.0.1.alpha31 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/edit/file_and_line_locator.rb
primary_connect_proto-0.4.0 vendor/bundle/ruby/2.6.0/gems/pry-0.13.1/lib/pry/commands/edit/file_and_line_locator.rb
primary_connect_proto-0.3.0 vendor/bundle/ruby/2.6.0/gems/pry-0.13.1/lib/pry/commands/edit/file_and_line_locator.rb
primary_connect_proto-0.2.0 vendor/bundle/ruby/2.6.0/gems/pry-0.13.1/lib/pry/commands/edit/file_and_line_locator.rb
primary_connect_proto-0.1.0 vendor/bundle/ruby/2.6.0/gems/pry-0.13.1/lib/pry/commands/edit/file_and_line_locator.rb
ory-client-0.0.1.alpha30 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/edit/file_and_line_locator.rb
ory-client-0.0.1.alpha29 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/edit/file_and_line_locator.rb
primary_connect_proto-0.0.6 vendor/bundle/ruby/2.6.0/gems/pry-0.13.1/lib/pry/commands/edit/file_and_line_locator.rb
ory-client-0.0.1.alpha28 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/edit/file_and_line_locator.rb
primary_connect_proto-0.0.5 vendor/bundle/ruby/2.6.0/gems/pry-0.13.1/lib/pry/commands/edit/file_and_line_locator.rb
ory-client-0.0.1.alpha27 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/edit/file_and_line_locator.rb
ory-client-0.0.1.alpha24 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/edit/file_and_line_locator.rb
primary_connect_proto-0.0.4 vendor/bundle/ruby/2.6.0/gems/pry-0.13.1/lib/pry/commands/edit/file_and_line_locator.rb
primary_connect_proto-0.0.3 vendor/bundle/ruby/2.6.0/gems/pry-0.13.1/lib/pry/commands/edit/file_and_line_locator.rb
ory-client-0.0.1.alpha23 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/edit/file_and_line_locator.rb
ory-kratos-client-0.8.0.alpha2 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/edit/file_and_line_locator.rb
ory-client-0.0.1.alpha21 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/edit/file_and_line_locator.rb