Sha256: e72dd1264e809de14436c7527e279262e509803adaabae3c8595512b63ece6c3

Contents?: true

Size: 1.18 KB

Versions: 39

Compression:

Stored size: 1.18 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.exist?(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, 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

39 entries across 39 versions & 14 rubygems

Version Path
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/pry-0.12.2/lib/pry/commands/edit/file_and_line_locator.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/pry-0.12.2/lib/pry/commands/edit/file_and_line_locator.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/pry-0.12.2/lib/pry/commands/edit/file_and_line_locator.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/pry-0.12.2/lib/pry/commands/edit/file_and_line_locator.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/pry-0.12.2/lib/pry/commands/edit/file_and_line_locator.rb
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/pry-0.11.3/lib/pry/commands/edit/file_and_line_locator.rb
chess_engine-0.0.2 vendor/bundle/gems/pry-0.12.2/lib/pry/commands/edit/file_and_line_locator.rb
chess_engine-0.0.1 vendor/bundle/gems/pry-0.12.2/lib/pry/commands/edit/file_and_line_locator.rb
xaiml-0.1.3 vendor/bundle/ruby/2.5.0/gems/pry-0.11.3/lib/pry/commands/edit/file_and_line_locator.rb
alimentos-alu0100945645-0.1.0 vendor/bundle/ruby/2.3.0/gems/pry-0.12.2/lib/pry/commands/edit/file_and_line_locator.rb
alimentos-alu0100945645-1.0.0 vendor/bundle/ruby/2.3.0/gems/pry-0.12.2/lib/pry/commands/edit/file_and_line_locator.rb
xaiml-0.1.2 vendor/bundle/ruby/2.5.0/gems/pry-0.11.3/lib/pry/commands/edit/file_and_line_locator.rb
pry-0.12.2-java lib/pry/commands/edit/file_and_line_locator.rb
pry-0.12.2 lib/pry/commands/edit/file_and_line_locator.rb
pry-0.12.1 lib/pry/commands/edit/file_and_line_locator.rb
pry-0.12.1-java lib/pry/commands/edit/file_and_line_locator.rb
pry-0.12.0 lib/pry/commands/edit/file_and_line_locator.rb
pry-0.12.0-java lib/pry/commands/edit/file_and_line_locator.rb
xaiml-0.1.1 vendor/bundle/ruby/2.5.0/gems/pry-0.11.3/lib/pry/commands/edit/file_and_line_locator.rb
xaiml-0.1.0 vendor/bundle/ruby/2.5.0/gems/pry-0.11.3/lib/pry/commands/edit/file_and_line_locator.rb