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, #match

Methods included from StringFunctions

#camelize, #prettify

Methods included from FileFunctions

#get_line, #get_lines, #n_lines, #normalize

Methods included from ParseFunctions

#get_int, #parse_steps, #syntax_valid?

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject


36
37
38
39
40
41
42
# File 'lib/byebug/commands/source.rb', line 36

def description
  prettify <<-EOD
    source <file>

    Executes file <file> containing byebug commands.
  EOD
end

.namesObject


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

def names
  %w(source)
end

Instance Method Details

#executeObject


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

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

  unless @state && @state.interface
    return errmsg(pr('source.errors.not_available'))
  end

  file = File.expand_path(@match[1]).strip
  unless File.exist?(file)
    return errmsg(pr('source.errors.not_found', file: file))
  end

  @state.interface.read_file(file)
end

#regexpObject


12
13
14
# File 'lib/byebug/commands/source.rb', line 12

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