Class: Gitlab::Shell::History
- Inherits:
-
Object
- Object
- Gitlab::Shell::History
- 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
-
#initialize(options = {}) ⇒ History
constructor
A new instance of History.
- #lines ⇒ Object
- #load ⇒ Object
- #push(line) ⇒ Object (also: #<<)
- #save ⇒ Object
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( = {}) @file_path = [:file_path] || DEFAULT_FILE_PATH Readline::HISTORY.clear end |
Instance Method Details
#lines ⇒ Object
26 27 28 |
# File 'lib/gitlab/shell_history.rb', line 26 def lines Readline::HISTORY.to_a.last(max_lines) end |
#load ⇒ Object
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 |
#save ⇒ Object
17 18 19 |
# File 'lib/gitlab/shell_history.rb', line 17 def save lines.each { |line| history_file&.puts line } end |