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.
6 7 8 9 |
# File 'lib/gitlab/shell_history.rb', line 6 def initialize(={}) @file_path = [:file_path] || DEFAULT_FILE_PATH Readline::HISTORY.clear end |
Instance Method Details
#lines ⇒ Object
24 25 26 |
# File 'lib/gitlab/shell_history.rb', line 24 def lines Readline::HISTORY.to_a.last(max_lines) end |
#load ⇒ Object
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 |
#save ⇒ Object
15 16 17 |
# File 'lib/gitlab/shell_history.rb', line 15 def save lines.each { |line| history_file.puts line if history_file } end |