Module: Pry::Command::Edit::FileAndLineLocator
- Defined in:
- lib/pry/commands/edit/file_and_line_locator.rb
Class Method Summary collapse
- .from_binding(target) ⇒ Object
- .from_code_object(code_object, filename_argument) ⇒ Object
- .from_exception(exception, backtrace_level) ⇒ Object
-
.from_filename_argument(filename_argument) ⇒ Object
when file and line are passed as a single arg, e.g my_file.rb:30.
Class Method Details
.from_binding(target) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/pry/commands/edit/file_and_line_locator.rb', line 8 def from_binding(target) if target.respond_to?(:source_location) target.source_location else target.eval("[__FILE__, __LINE__]") end end |
.from_code_object(code_object, filename_argument) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/pry/commands/edit/file_and_line_locator.rb', line 16 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 |
.from_exception(exception, backtrace_level) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/pry/commands/edit/file_and_line_locator.rb', line 24 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 |
.from_filename_argument(filename_argument) ⇒ Object
when file and line are passed as a single arg, e.g my_file.rb:30
38 39 40 41 42 |
# File 'lib/pry/commands/edit/file_and_line_locator.rb', line 38 def from_filename_argument(filename_argument) f = File.(filename_argument) l = f.sub!(/:(\d+)$/, "") ? Regexp.last_match(1).to_i : 1 [f, l] end |