Class: Pry::History
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/history.rb
Overview
The History class is responsible for maintaining the user’s input history, both internally and within Readline.
Instance Attribute Summary collapse
-
#history_line_count ⇒ Integer
readonly
Total number of lines, including original lines.
-
#loader ⇒ Object
Returns the value of attribute loader.
-
#original_lines ⇒ Fixnum
readonly
Number of lines in history when Pry first loaded.
-
#saver ⇒ Object
Returns the value of attribute saver.
Class Method Summary collapse
Instance Method Summary collapse
-
#clear ⇒ Object
Clear this session’s history.
-
#filter(history) ⇒ Array<String>
Filter the history with the histignore options.
-
#initialize(options = {}) ⇒ History
constructor
A new instance of History.
-
#load ⇒ Integer
Load the input history using ‘History.loader`.
-
#push(line) ⇒ String
(also: #<<)
Add a line to the input history, ignoring blank and duplicate lines.
-
#session_line_count ⇒ Fixnum
The number of lines in history from just this session.
-
#to_a ⇒ Array<String>
Return an Array containing all stored history.
Constructor Details
#initialize(options = {}) ⇒ History
Returns a new instance of History.
29 30 31 32 33 34 35 36 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/history.rb', line 29 def initialize( = {}) @history = [:history] || [] @history_line_count = @history.count @file_path = [:file_path] @original_lines = 0 @loader = method(:read_from_file) @saver = method(:save_to_file) end |
Instance Attribute Details
#history_line_count ⇒ Integer (readonly)
Returns total number of lines, including original lines.
27 28 29 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/history.rb', line 27 def history_line_count @history_line_count end |
#loader ⇒ Object
Returns the value of attribute loader.
21 22 23 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/history.rb', line 21 def loader @loader end |
#original_lines ⇒ Fixnum (readonly)
Returns Number of lines in history when Pry first loaded.
24 25 26 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/history.rb', line 24 def original_lines @original_lines end |
#saver ⇒ Object
Returns the value of attribute saver.
21 22 23 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/history.rb', line 21 def saver @saver end |
Class Method Details
.default_file ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/history.rb', line 7 def self.default_file history_file = if (xdg_home = Pry::Env['XDG_DATA_HOME']) # See XDG Base Directory Specification at # https://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html xdg_home + '/pry/pry_history' elsif File.exist?(File.('~/.pry_history')) '~/.pry_history' else '~/.local/share/pry/pry_history' end File.(history_file) end |
Instance Method Details
#clear ⇒ Object
Clear this session’s history. This won’t affect the contents of the history file.
74 75 76 77 78 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/history.rb', line 74 def clear @history.clear @history_line_count = 0 @original_lines = 0 end |
#filter(history) ⇒ Array<String>
Filter the history with the histignore options
95 96 97 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/history.rb', line 95 def filter(history) history.select { |l| l unless should_ignore?(l) } end |
#load ⇒ Integer
Load the input history using ‘History.loader`.
40 41 42 43 44 45 46 47 48 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/history.rb', line 40 def load @loader.call do |line| next if invalid_readline_line?(line) @history << line.chomp @original_lines += 1 @history_line_count += 1 end end |
#push(line) ⇒ String Also known as: <<
Add a line to the input history, ignoring blank and duplicate lines.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/history.rb', line 53 def push(line) return line if line.empty? || invalid_readline_line?(line) begin last_line = @history[-1] rescue IndexError last_line = nil end return line if line == last_line @history << line @history_line_count += 1 @saver.call(line) if !should_ignore?(line) && Pry.config.history_save line end |
#session_line_count ⇒ Fixnum
Returns The number of lines in history from just this session.
81 82 83 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/history.rb', line 81 def session_line_count @history_line_count - @original_lines end |