Class: Byebug::Setting
- Inherits:
-
Object
show all
- Defined in:
- lib/byebug/setting.rb
Overview
Parent class for all byebug settings.
Direct Known Subclasses
AutoirbSetting, AutolistSetting, AutoprySetting, AutosaveSetting, BasenameSetting, CallstyleSetting, FullpathSetting, HistfileSetting, HistsizeSetting, LinetraceSetting, ListsizeSetting, PostMortemSetting, SavefileSetting, StackOnErrorSetting, WidthSetting
Constant Summary
collapse
- DEFAULT =
false
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Setting.
14
15
16
|
# File 'lib/byebug/setting.rb', line 14
def initialize
@value = self.class::DEFAULT
end
|
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
10
11
12
|
# File 'lib/byebug/setting.rb', line 10
def value
@value
end
|
Class Method Details
.[](name) ⇒ Object
46
47
48
|
# File 'lib/byebug/setting.rb', line 46
def [](name)
settings[name].value
end
|
.[]=(name, value) ⇒ Object
50
51
52
|
# File 'lib/byebug/setting.rb', line 50
def []=(name, value)
settings[name].value = value
end
|
.find(shortcut) ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/byebug/setting.rb', line 54
def find(shortcut)
abbr = /^no/.match?(shortcut) ? shortcut[2..-1] : shortcut
matches = settings.select do |key, value|
key =~ (value.boolean? ? /#{abbr}/ : /#{shortcut}/)
end
matches.size == 1 ? matches.values.first : nil
end
|
.help_all ⇒ Object
TODO:
DRY this up. Very similar code exists in the CommandList class
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/byebug/setting.rb', line 65
def help_all
output = " List of supported settings:\n\n"
width = settings.keys.max_by(&:size).size
settings.each_value do |sett|
output += format(
" %<name>-#{width}s -- %<description>s\n",
name: sett.to_sym,
description: sett.banner
)
end
output + "\n"
end
|
.settings ⇒ Object
42
43
44
|
# File 'lib/byebug/setting.rb', line 42
def settings
@settings ||= {}
end
|
Instance Method Details
#boolean? ⇒ Boolean
18
19
20
|
# File 'lib/byebug/setting.rb', line 18
def boolean?
[true, false].include?(value)
end
|
#help ⇒ Object
28
29
30
|
# File 'lib/byebug/setting.rb', line 28
def help
prettify(banner)
end
|
#integer? ⇒ Boolean
22
23
24
25
26
|
# File 'lib/byebug/setting.rb', line 22
def integer?
Integer(value) ? true : false
rescue ArgumentError
false
end
|
#to_s ⇒ Object
37
38
39
|
# File 'lib/byebug/setting.rb', line 37
def to_s
"#{to_sym} is #{value ? 'on' : 'off'}\n"
end
|
#to_sym ⇒ Object
32
33
34
35
|
# File 'lib/byebug/setting.rb', line 32
def to_sym
name = self.class.name.gsub(/^Byebug::/, "").gsub(/Setting$/, "")
name.gsub(/(.)([A-Z])/, '\1_\2').downcase.to_sym
end
|