Class: DEBUGGER__::Console
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/debug/console.rb |
Constant Summary
-
FH =
# File 'lib/debug/console.rb', line 170"# Today's OMIKUJI: "
Class Method Summary
- .new ⇒ Console constructor
Instance Method Summary
Constructor Details
.new ⇒ Console
# File 'lib/debug/console.rb', line 183
def initialize @init_history_lines = nil end
Instance Method Details
#deactivate
[ GitHub ]# File 'lib/debug/console.rb', line 193
def deactivate if history && @init_history_lines added_records = history.to_a[@init_history_lines .. -1] path = history_file() max = CONFIG[:save_history] if !added_records.empty? && !path.empty? orig_records = read_history_file open(history_file(), 'w'){|f| (orig_records + added_records).last(max).each{|line| # Use scrub to handle encoding issues gracefully scrubbed_line = line.scrub.strip if !line.start_with?(FH) && !scrubbed_line.empty? f.puts scrubbed_line end } } end end end
#history_file
[ GitHub ]# File 'lib/debug/console.rb', line 155
def history_file case when (path = CONFIG[:history_file]) && !path.empty? path = File. (path) when (path = File. ("~/.rdbg_history")) && File.exist?(path) # for compatibility # path else state_dir = ENV['XDG_STATE_HOME'] || File.join(Dir.home, '.local', 'state') path = File.join(File. (state_dir), 'rdbg', 'history') end FileUtils.mkdir_p(File.dirname(path)) unless File.exist?(path) path end
#load_history
[ GitHub ]# File 'lib/debug/console.rb', line 214
def load_history read_history_file.each{|line| # Use scrub to handle encoding issues gracefully, then strip line.scrub! line.strip! history << line unless line.empty? } if history.empty? history.count end
#load_history_if_not_loaded
[ GitHub ]# File 'lib/debug/console.rb', line 187
def load_history_if_not_loaded return if @init_history_lines @init_history_lines = load_history end
#read_history_file
[ GitHub ]# File 'lib/debug/console.rb', line 172
def read_history_file if history && File.exist?(path = history_file()) f = (['', 'DAI-', 'CHU-', 'SHO-'].map{|e| e'KICHI'}['KYO']).sample # Read history file and scrub invalid characters to prevent encoding errors lines = File.readlines(path).map(&:scrub) ["#{FH}#{f}".dup] + lines else [] end end