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.



6
7
8
9
# File 'lib/gitlab/shell_history.rb', line 6

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

Instance Method Details

#linesObject



24
25
26
# File 'lib/gitlab/shell_history.rb', line 24

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

#loadObject



11
12
13
# File 'lib/gitlab/shell_history.rb', line 11

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

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



19
20
21
# File 'lib/gitlab/shell_history.rb', line 19

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

#saveObject



15
16
17
# File 'lib/gitlab/shell_history.rb', line 15

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