Sha256: c124c8c9855c94b1aaa1eef2bef7a164fd4be64552260549d66826d1218ef096

Contents?: true

Size: 1.28 KB

Versions: 79

Compression:

Stored size: 1.28 KB

Contents

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

        def from_code_object(code_object, filename_argument)
          if File.exists?(code_object.source_file.to_s)
            [code_object.source_file, code_object.source_line]
          else
            raise CommandError, "Cannot find a file for #{filename_argument}!"
          end
        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?
          raise CommandError, "Cannot edit exceptions raised in REPL." if Pry.eval_path == file_name

          file_name = RbxPath.convert_path_to_full(file_name) if RbxPath.is_core_path?(file_name)

          [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+)$/, "") ? $1.to_i : 1
          [f, l]
        end
      end
    end
  end
end

Version data entries

79 entries across 79 versions & 5 rubygems

Version Path
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/pry-0.9.12.6/lib/pry/commands/edit/file_and_line_locator.rb
pry-0.9.12.6 lib/pry/commands/edit/file_and_line_locator.rb
pry-0.9.12.6-i386-mswin32 lib/pry/commands/edit/file_and_line_locator.rb
pry-0.9.12.6-i386-mingw32 lib/pry/commands/edit/file_and_line_locator.rb
pry-0.9.12.6-java lib/pry/commands/edit/file_and_line_locator.rb
pry-0.9.12.5 lib/pry/commands/edit/file_and_line_locator.rb
pry-0.9.12.5-i386-mswin32 lib/pry/commands/edit/file_and_line_locator.rb
pry-0.9.12.5-i386-mingw32 lib/pry/commands/edit/file_and_line_locator.rb
pry-0.9.12.5-java lib/pry/commands/edit/file_and_line_locator.rb
pry-0.9.12.4 lib/pry/commands/edit/file_and_line_locator.rb
pry-0.9.12.4-i386-mswin32 lib/pry/commands/edit/file_and_line_locator.rb
pry-0.9.12.4-i386-mingw32 lib/pry/commands/edit/file_and_line_locator.rb
pry-0.9.12.4-java lib/pry/commands/edit/file_and_line_locator.rb
pry-0.9.12.3 lib/pry/commands/edit/file_and_line_locator.rb
pry-0.9.12.3-i386-mswin32 lib/pry/commands/edit/file_and_line_locator.rb
pry-0.9.12.3-i386-mingw32 lib/pry/commands/edit/file_and_line_locator.rb
pry-0.9.12.3-java lib/pry/commands/edit/file_and_line_locator.rb
torquebox-console-0.3.0 vendor/bundle/jruby/1.9/gems/pry-0.9.12-java/lib/pry/commands/edit/file_and_line_locator.rb
sshp-0.0.2 vendor/ruby/1.9.1/gems/pry-0.9.12.2/lib/pry/commands/edit/file_and_line_locator.rb
sshp-0.0.1 vendor/ruby/1.9.1/gems/pry-0.9.12.2/lib/pry/commands/edit/file_and_line_locator.rb