Class: Debugger::Command

Inherits:
Object
  • Object
show all
Includes:
Columnize
Defined in:
lib/ruby-debug/command.rb

Overview

:nodoc:

Defined Under Namespace

Classes: SubcmdStruct

Constant Summary collapse

DEF_OPTIONS =
{
  :allow_in_control     => false,
  :allow_in_post_mortem => true,
  :event => true,
  :always_run => 0,
  :unknown => false,
  :need_context => false,
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(state) ⇒ Command

Returns a new instance of Command.



148
149
150
# File 'lib/ruby-debug/command.rb', line 148

def initialize(state)
  @state = state
end

Class Method Details

.commandsObject



28
29
30
# File 'lib/ruby-debug/command.rb', line 28

def commands
  @commands ||= []
end

.inherited(klass) ⇒ Object



41
42
43
44
45
46
# File 'lib/ruby-debug/command.rb', line 41

def inherited(klass)
  DEF_OPTIONS.each do |o, v|
    klass.options[o] = v if klass.options[o].nil?
  end
  commands << klass
end

.load_commandsObject



48
49
50
51
52
53
54
55
# File 'lib/ruby-debug/command.rb', line 48

def load_commands
  Dir[File.join(Debugger.const_get(:RUBY_DEBUG_DIR), 'commands', '*')].each do |file|
    require file if file =~ /\.rb$/
  end
  Debugger.constants.grep(/Functions$/).map { |name| Debugger.const_get(name) }.each do |mod|
    include mod
  end
end

.method_missing(meth, *args, &block) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ruby-debug/command.rb', line 57

def method_missing(meth, *args, &block)
  if meth.to_s =~ /^(.+?)=$/
    @options[$1.intern] = args.first
  else
    if @options.has_key?(meth)
      @options[meth]
    else
      super
    end
  end
end

.optionsObject



69
70
71
# File 'lib/ruby-debug/command.rb', line 69

def options
  @options ||= {}
end

.register_setting_get(name, &block) ⇒ Object



117
118
119
120
# File 'lib/ruby-debug/command.rb', line 117

def register_setting_get(name, &block)
  settings_map[name] ||= {}
  settings_map[name][:getter] = block
end

.register_setting_set(name, &block) ⇒ Object



122
123
124
125
# File 'lib/ruby-debug/command.rb', line 122

def register_setting_set(name, &block)
  settings_map[name] ||= {}
  settings_map[name][:setter] = block
end

.register_setting_var(name, default) ⇒ Object



110
111
112
113
114
115
# File 'lib/ruby-debug/command.rb', line 110

def register_setting_var(name, default)
  var_name = "@@#{name}"
  class_variable_set(var_name, default)
  register_setting_get(name) { class_variable_get(var_name) }
  register_setting_set(name) { |value| class_variable_set(var_name, value) }
end

.settingsObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/ruby-debug/command.rb', line 78

def settings
  unless true and defined? @settings and @settings
    @settings = Object.new
    map = settings_map
    c = class << @settings; self end
    if c.respond_to?(:funcall)
      c.funcall(:define_method, :[]) do |name|
        raise "No such setting #{name}" unless map.has_key?(name)
        map[name][:getter].call
      end
    else
      c.send(:define_method, :[]) do |name|
        raise "No such setting #{name}" unless map.has_key?(name)
        map[name][:getter].call
      end
    end
    c = class << @settings; self end
    if c.respond_to?(:funcall)
      c.funcall(:define_method, :[]=) do |name, value|
        raise "No such setting #{name}" unless map.has_key?(name)
        map[name][:setter].call(value)
      end
    else
      c.send(:define_method, :[]=) do |name, value|
        raise "No such setting #{name}" unless map.has_key?(name)
        map[name][:setter].call(value)
      end
    end
  end
  @settings
end

.settings_mapObject



73
74
75
# File 'lib/ruby-debug/command.rb', line 73

def settings_map
  @@settings_map ||= {}
end

Instance Method Details

#find(subcmds, param) ⇒ Object

Find param in subcmds. param id downcased and can be abbreviated to the minimum length listed in the subcommands



16
17
18
19
20
21
22
23
24
25
# File 'lib/ruby-debug/command.rb', line 16

def find(subcmds, param)
  param.downcase!
  for try_subcmd in subcmds do
    if (param.size >= try_subcmd.min) and
        (try_subcmd.name[0..param.size-1] == param)
      return try_subcmd
    end
  end
  return nil
end

#match(input) ⇒ Object



152
153
154
# File 'lib/ruby-debug/command.rb', line 152

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