lib/archer.rb in archer-rails-0.1.0 vs lib/archer.rb in archer-rails-0.1.1
- old
+ new
@@ -18,40 +18,36 @@
def self.clear
quietly do
Archer::History.where(user: user).delete_all
end
- Readline::HISTORY.clear rescue nil
+ Readline::HISTORY.clear
true
end
def self.start
history = nil
begin
quietly do
- history = Archer::History.where(user: user).first_or_initialize
+ history = Archer::History.find_by(user: user)
end
- rescue
+ rescue ActiveRecord::StatementInvalid
warn "[archer] Create table to enable history"
end
- if history && history.persisted?
- File.write(history_file, history.commands)
+ if history
+ Readline::HISTORY.push(*history.commands.split("\n"))
end
-
- require "irb/ext/save-history"
- IRB.conf[:SAVE_HISTORY] = limit
- IRB.conf[:HISTORY_FILE] = history_file
end
def self.save
quietly do
history = Archer::History.where(user: user).first_or_initialize
- history.commands = File.read(history_file)
+ history.commands = Readline::HISTORY.to_a.last(limit).join("\n")
history.save
end
- rescue
- # do nothing
+ rescue ActiveRecord::StatementInvalid
+ warn "[archer] Unable to save history"
end
# private
def self.quietly
ActiveRecord::Base.logger.silence do