Class: DEBUGGER__::Console
Constant Summary collapse
- FH =
"# Today's OMIKUJI: "
Instance Method Summary collapse
- #deactivate ⇒ Object
- #history_file ⇒ Object
-
#initialize ⇒ Console
constructor
A new instance of Console.
- #load_history ⇒ Object
- #load_history_if_not_loaded ⇒ Object
- #read_history_file ⇒ Object
Constructor Details
#initialize ⇒ Console
Returns a new instance of Console.
176 177 178 |
# File 'lib/debug/console.rb', line 176 def initialize @init_history_lines = nil end |
Instance Method Details
#deactivate ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/debug/console.rb', line 186 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| if !line.start_with?(FH) && !line.strip.empty? f.puts line.strip end } } end end end |
#history_file ⇒ Object
155 156 157 158 159 160 161 162 163 |
# File 'lib/debug/console.rb', line 155 def history_file history_file = CONFIG[:history_file] if !history_file.empty? File.(history_file) else history_file end end |
#load_history ⇒ Object
205 206 207 208 209 210 211 |
# File 'lib/debug/console.rb', line 205 def load_history read_history_file.each{|line| line.strip! history << line unless line.empty? } if history.empty? history.count end |
#load_history_if_not_loaded ⇒ Object
180 181 182 183 184 |
# File 'lib/debug/console.rb', line 180 def load_history_if_not_loaded return if @init_history_lines @init_history_lines = load_history end |