Class: Byebug::SourceCommand

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

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



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

def description
  %{source FILE\texecutes a file containing byebug commands}
end

.namesObject



24
25
26
# File 'lib/byebug/commands/source.rb', line 24

def names
  %w(source)
end

Instance Method Details

#executeObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/byebug/commands/source.rb', line 9

def execute
  return print SourceCommand.help(nil) if
    SourceCommand.names.include?(@match[0])

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

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

#regexpObject



5
6
7
# File 'lib/byebug/commands/source.rb', line 5

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