Class: Byebug::SourceCommand

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

Overview

Implements byebug “source” command.

Constant Summary

Constants inherited from Command

Command::DEF_OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

commands, help, inherited, #initialize, load_commands, #match, method_missing, options, register_setting_get, register_setting_set, register_setting_var, settings, settings_map

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject



30
31
32
33
34
# File 'lib/byebug/commands/source.rb', line 30

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

.namesObject



26
27
28
# File 'lib/byebug/commands/source.rb', line 26

def names
  %w(source)
end

Instance Method Details

#executeObject



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

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



7
8
9
# File 'lib/byebug/commands/source.rb', line 7

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