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.



38
39
40
41
# File 'lib/byebug/command.rb', line 38

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



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

def allow_in_control
  @allow_in_control
end

.allow_in_post_mortemObject

Special methods to allow command filtering in processors



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

def allow_in_post_mortem
  @allow_in_post_mortem
end

.always_runObject



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

def always_run
  @always_run ||= 0
end

Instance Attribute Details

#processorObject (readonly)

Returns the value of attribute processor.



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

def processor
  @processor
end

Class Method Details

.columnize(width) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/byebug/command.rb', line 88

def columnize(width)
  format(
    "  %-<name>#{width}s -- %<description>s\n",
    name: to_s,
    description: short_description
  )
end

.helpObject

Default help text for a command.



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

def help
  prettify(description)
end

.match(input) ⇒ Object

Command’s regexp match against an input



106
107
108
# File 'lib/byebug/command.rb', line 106

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

.to_sObject

Name of the command, as executed by the user.



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

def to_s
  name
    .split("::")
    .map { |n| n.gsub(/Command$/, "").downcase if /Command$/.match?(n) }
    .compact
    .join(" ")
end

Instance Method Details

#argumentsObject



51
52
53
# File 'lib/byebug/command.rb', line 51

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

#contextObject



43
44
45
# File 'lib/byebug/command.rb', line 43

def context
  @context ||= processor.context
end

#frameObject



47
48
49
# File 'lib/byebug/command.rb', line 47

def frame
  @frame ||= context.frame
end