Class: Byebug::SourceCommand

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

Overview

Execute a file containing byebug commands.

It can be used to restore a previously saved debugging session.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

commands, find, format_subcmd, format_subcmds, help, inherited, #initialize, load_commands, #match

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject



32
33
34
35
36
# File 'lib/byebug/commands/source.rb', line 32

def description
  %(source <file>

    Executes file <file> containing byebug commands.)
end

.namesObject



28
29
30
# File 'lib/byebug/commands/source.rb', line 28

def names
  %w(source)
end

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/byebug/commands/source.rb', line 14

def execute
  return puts(self.class.help) if self.class.names.include?(@match[0])

  file = File.expand_path(@match[1]).strip
  return errmsg("File \"#{file}\" not found") unless File.exist?(file)

  if @state && @state.interface
    @state.interface.command_queue += File.open(file).readlines
  else
    Byebug.run_script(file, @state)
  end
end

#regexpObject



10
11
12
# File 'lib/byebug/commands/source.rb', line 10

def regexp
  /^\s* so(?:urce)? (?:\s+(\S+))? \s*$/x
end