Class: Gitlab::Shell::History

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/shell_history.rb

Constant Summary collapse

DEFAULT_HISTFILESIZE =
200
DEFAULT_FILE_PATH =
File.join(Dir.home, '.gitlab_shell_history')

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ History

Returns a new instance of History.



8
9
10
11
# File 'lib/gitlab/shell_history.rb', line 8

def initialize(options = {})
  @file_path = options[:file_path] || DEFAULT_FILE_PATH
  Readline::HISTORY.clear
end

Instance Method Details

#linesObject



26
27
28
# File 'lib/gitlab/shell_history.rb', line 26

def lines
  Readline::HISTORY.to_a.last(max_lines)
end

#loadObject



13
14
15
# File 'lib/gitlab/shell_history.rb', line 13

def load
  read_from_file { |line| Readline::HISTORY << line.chomp }
end

#push(line) ⇒ Object Also known as: <<



21
22
23
# File 'lib/gitlab/shell_history.rb', line 21

def push(line)
  Readline::HISTORY << line
end

#saveObject



17
18
19
# File 'lib/gitlab/shell_history.rb', line 17

def save
  lines.each { |line| history_file&.puts line }
end