Class: Byebug::Command

Inherits:
Object
  • Object
show all
Extended by:
Helpers::StringHelper, Forwardable
Defined in:
lib/byebug/command.rb

Overview

Parent class of all byebug commands.

Subclass it and name the subclass ending with the word Command to implement your own custom command.

class MyCustomCommand < Command

def self.regexp
  /custom_regexp/
end

def self.description
  'Custom long desc'
end

def.short_description
  'Custom short desc'
end

def execute
  # My command's implementation
end

end

Examples:

Define a custom command

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::StringHelper

camelize, deindent, prettify

Constructor Details

#initialize(processor, input = self.class.to_s) ⇒ Command

Returns a new instance of Command.



36
37
38
39
# File 'lib/byebug/command.rb', line 36

def initialize(processor, input = self.class.to_s)
  @processor = processor
  @match = match(input)
end

Class Attribute Details

.allow_in_controlObject

Special methods to allow command filtering in processors



67
68
69
# File 'lib/byebug/command.rb', line 67

def allow_in_control
  @allow_in_control
end

.allow_in_post_mortemObject

Special methods to allow command filtering in processors



67
68
69
# File 'lib/byebug/command.rb', line 67

def allow_in_post_mortem
  @allow_in_post_mortem
end

.always_runObject



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

def always_run
  @always_run ||= 0
end

Instance Attribute Details

#processorObject (readonly)

Returns the value of attribute processor.



34
35
36
# File 'lib/byebug/command.rb', line 34

def processor
  @processor
end

Class Method Details

.columnize(width) ⇒ Object



86
87
88
# File 'lib/byebug/command.rb', line 86

def columnize(width)
  format("  %-#{width}s -- %s\n", to_s, short_description)
end

.helpObject

Default help text for a command.



93
94
95
# File 'lib/byebug/command.rb', line 93

def help
  prettify(description)
end

.match(input) ⇒ Object

Command’s regexp match against an input



100
101
102
# File 'lib/byebug/command.rb', line 100

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

.to_sObject

Name of the command, as executed by the user.



78
79
80
81
82
83
84
# File 'lib/byebug/command.rb', line 78

def to_s
  name
    .split('::')
    .map { |n| n.gsub(/Command$/, '').downcase if n =~ /Command$/ }
    .compact
    .join(' ')
end

Instance Method Details

#argumentsObject



49
50
51
# File 'lib/byebug/command.rb', line 49

def arguments
  @match[0].split(' ').drop(1).join(' ')
end

#contextObject



41
42
43
# File 'lib/byebug/command.rb', line 41

def context
  @context ||= processor.context
end

#frameObject



45
46
47
# File 'lib/byebug/command.rb', line 45

def frame
  @frame ||= context.frame
end