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.
197 198 199 |
# File 'lib/debug/console.rb', line 197 def initialize @init_history_lines = nil end |
Instance Method Details
#deactivate ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/debug/console.rb', line 207 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
176 177 178 179 180 181 182 183 184 |
# File 'lib/debug/console.rb', line 176 def history_file history_file = CONFIG[:history_file] if !history_file.empty? File.(history_file) else history_file end end |
#load_history ⇒ Object
226 227 228 229 230 231 |
# File 'lib/debug/console.rb', line 226 def load_history read_history_file.count{|line| line.strip! history << line unless line.empty? } end |
#load_history_if_not_loaded ⇒ Object
201 202 203 204 205 |
# File 'lib/debug/console.rb', line 201 def load_history_if_not_loaded return if @init_history_lines @init_history_lines = load_history end |
#read_history_file ⇒ Object
188 189 190 191 192 193 194 195 |
# File 'lib/debug/console.rb', line 188 def read_history_file if history && File.exist?(path = history_file) f = (['', 'DAI-', 'CHU-', 'SHO-'].map{|e| e+'KICHI'}+['KYO']).sample ["#{FH}#{f}".dup] + File.readlines(path) else [] end end |