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.

Instance Method Summary collapse

Methods inherited from Command

#help, #initialize, #match, subcommands, to_name

Methods included from Helpers::StringHelper

#camelize, #prettify

Constructor Details

This class inherits a constructor from Byebug::Command

Instance Method Details

#descriptionObject



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

def description
  <<-EOD
    source <file>

    Executes file <file> containing byebug commands.
  EOD
end

#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(help) unless @match[1]

  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