Class: Byebug::EditCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/byebug/commands/edit.rb

Overview

Edit a file from byebug’s prompt.

Instance Attribute Summary

Attributes inherited from Command

#processor

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

#arguments, columnize, #context, #frame, help, #initialize, match, to_s

Methods included from Helpers::StringHelper

#camelize, #deindent, #prettify

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/byebug/commands/edit.rb', line 17

def self.description
  <<-DESCRIPTION
    edit[ file:lineno]

    #{short_description}

    With no argumnt, edits file containing most re line listed. Editing
    targets can also be specified to start editing at a specific line in a
    specific file
  DESCRIPTION
end

.regexpObject



13
14
15
# File 'lib/byebug/commands/edit.rb', line 13

def self.regexp
  /^\s* ed(?:it)? (?:\s+(\S+))? \s*$/x
end

.short_descriptionObject



29
30
31
# File 'lib/byebug/commands/edit.rb', line 29

def self.short_description
  "Edits source files"
end

Instance Method Details

#executeObject



33
34
35
36
37
38
39
40
41
# File 'lib/byebug/commands/edit.rb', line 33

def execute
  file, line = location(@match[1])
  return edit_error("not_exist", file) unless File.exist?(file)
  return edit_error("not_readable", file) unless File.readable?(file)

  cmd = line ? "#{editor} +#{line} #{file}" : "#{editor} #{file}"

  Kernel.system(cmd)
end