class ThorRepl::History
Attributes
history_file[R]
Public Class Methods
new(readline_history: Readline::HISTORY, history_file_path: ThorRepl::HISTORY_FILE_PATH)
click to toggle source
# File lib/thor_repl/history.rb, line 6 def initialize(readline_history: Readline::HISTORY, history_file_path: ThorRepl::HISTORY_FILE_PATH) @readline_history = readline_history @history_file = history_file_path && File.expand_path(history_file_path) end
with_history(**opts, &block)
click to toggle source
# File lib/thor_repl/history.rb, line 11 def self.with_history(**opts, &block) history = self.new(**opts) history.read_history block.call ensure history.write_history end
Public Instance Methods
read_history()
click to toggle source
# File lib/thor_repl/history.rb, line 19 def read_history if history_file && File.exists?(history_file) IO.readlines(history_file).each { |e| @readline_history << e.chomp } end end
write_history()
click to toggle source
# File lib/thor_repl/history.rb, line 25 def write_history if history_file File.open(history_file, "w") { |f| f.puts(*Array(@readline_history)) } end end