Class: Byebug::Command

Inherits:
Object
  • Object
show all
Extended by:
StringFunctions, Forwardable
Includes:
FileFunctions, ParseFunctions
Defined in:
lib/byebug/command.rb

Overview

Parent class of all byebug commands.

Subclasses need to implement a `regexp` and an `execute` command.

Defined Under Namespace

Classes: Subcmd

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#initialize(state) ⇒ Command

Returns a new instance of Command.


19
20
21
# File 'lib/byebug/command.rb', line 19

def initialize(state)
  @match, @state = nil, state
end

Class Attribute Details

.allow_in_controlObject

Returns the value of attribute allow_in_control


70
71
72
# File 'lib/byebug/command.rb', line 70

def allow_in_control
  @allow_in_control
end

.allow_in_post_mortemObject


73
74
75
# File 'lib/byebug/command.rb', line 73

def allow_in_post_mortem
  !defined?(@allow_in_post_mortem) ? true : false
end

.always_runObject


77
78
79
# File 'lib/byebug/command.rb', line 77

def always_run
  @always_run ||= 0
end

Class Method Details

.commandsObject


118
119
120
# File 'lib/byebug/command.rb', line 118

def commands
  @commands ||= []
end

.find(subcmds, str) ⇒ Object


89
90
91
92
93
94
95
96
97
98
# File 'lib/byebug/command.rb', line 89

def find(subcmds, str)
  str.downcase!
  subcmds.each do |subcmd|
    if (str.size >= subcmd.min) && (subcmd.name[0..str.size - 1] == str)
      return subcmd
    end
  end

  nil
end

.format_subcmd(subcmd_name) ⇒ Object


100
101
102
103
104
105
106
# File 'lib/byebug/command.rb', line 100

def format_subcmd(subcmd_name)
  subcmd = find(self::Subcommands, subcmd_name)
  return "Invalid \"#{names.join('|')}\" " \
         "subcommand \"#{args[1]}\"." unless subcmd

  "\n  #{subcmd.help}.\n\n"
end

.format_subcmdsObject


108
109
110
111
112
113
114
115
116
# File 'lib/byebug/command.rb', line 108

def format_subcmds
  header = names.join('|')
  s = "  List of \"#{header}\" subcommands:\n  --\n"
  w = self::Subcommands.map(&:name).max_by(&:size).size
  self::Subcommands.each do |subcmd|
    s += format("  %s %-#{w}s -- %s\n", header, subcmd.name, subcmd.help)
  end
  s + "\n"
end

.help(subcmd = nil) ⇒ Object


81
82
83
84
85
86
87
# File 'lib/byebug/command.rb', line 81

def help(subcmd = nil)
  return format_subcmd(subcmd) if subcmd

  output = description
  output += format_subcmds if defined? self::Subcommands
  output
end

.inherited(klass) ⇒ Object


122
123
124
# File 'lib/byebug/command.rb', line 122

def inherited(klass)
  commands << klass
end

Instance Method Details

#match(input) ⇒ Object


23
24
25
# File 'lib/byebug/command.rb', line 23

def match(input)
  @match = regexp.match(input)
end