Class: TestLauncher::Shell::HistoryRunner

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/test_launcher/shell/history_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(shell: Shell::Runner.new, history_path: "/tmp/test_launcher__history") ⇒ HistoryRunner

delegates to @shell



9
10
11
12
# File 'lib/test_launcher/shell/history_runner.rb', line 9

def initialize(shell: Shell::Runner.new, history_path: "/tmp/test_launcher__history")
  @shell = shell
  @history_path = history_path
end

Instance Method Details

#__getobj__Object



36
37
38
# File 'lib/test_launcher/shell/history_runner.rb', line 36

def __getobj__
  @shell
end

#exec(cmd) ⇒ Object



14
15
16
17
# File 'lib/test_launcher/shell/history_runner.rb', line 14

def exec(cmd)
  record(cmd)
  @shell.exec(cmd)
end

#recallObject



32
33
34
# File 'lib/test_launcher/shell/history_runner.rb', line 32

def recall
  @recall ||= File.file?(@history_path) && File.read(@history_path).chomp
end

#record(cmd) ⇒ Object



28
29
30
# File 'lib/test_launcher/shell/history_runner.rb', line 28

def record(cmd)
  File.write(@history_path, cmd)
end

#reexecObject



19
20
21
22
23
24
25
26
# File 'lib/test_launcher/shell/history_runner.rb', line 19

def reexec
  if recall
    @shell.exec(recall)
  else
    warn "Cannot rerun: history file not found or is empty"
    exit
  end
end