Module: TestConsole::History

Defined in:
lib/test_console/history.rb

Constant Summary collapse

LIMIT =
1000
LOCATION =
"#{ENV['HOME']}/.tc_history"

Class Method Summary collapse

Class Method Details

.add(line) ⇒ Object



7
8
9
# File 'lib/test_console/history.rb', line 7

def add line
  Readline::HISTORY.push line
end

.readObject



11
12
13
14
15
16
17
18
# File 'lib/test_console/history.rb', line 11

def read
  if File.exists?(LOCATION)
    File.open(LOCATION) do |file|
      history = Marshal.load(file)
      history.each {|h| Readline::HISTORY.push h} if history
    end
  end
end

.writeObject



20
21
22
23
24
25
26
27
# File 'lib/test_console/history.rb', line 20

def write
  history = Readline::HISTORY.to_a
  history = (history.reverse[0, LIMIT]).reverse

  File.open(LOCATION, 'w+') do |file|
    Marshal.dump(history, file)
  end
end