Skip to content

Commit

Permalink
Pry.input_history -> Pry.history, Pry::InputHistory -> Pry::History
Browse files Browse the repository at this point in the history
  • Loading branch information
rf- committed Sep 5, 2011
1 parent 226f1ae commit a1a7cdc
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions lib/pry/default_commands/input.rb
Expand Up @@ -97,7 +97,7 @@ module DefaultCommands

command "hist", "Show and replay Readline history. Type `hist --help` for more info. Aliases: history" do |*args|
# exclude the current command from history.
history = Pry.input_history.to_a[0..-2]
history = Pry.history.to_a[0..-2]

opts = Slop.parse!(args) do |opt|
opt.banner "Usage: hist [--replay START..END] [--clear] [--grep PATTERN] [--head N] [--tail N] [--help] [--save [START..END] file.txt]\n"
Expand Down Expand Up @@ -170,7 +170,7 @@ module DefaultCommands
opt.on "save", "Save history to a file. --save [start..end] output.txt. Pry commands are excluded from saved history.", true, :as => Range

opt.on :c, :clear, 'Clear the history', :unless => :grep do
Pry.input_history.clear
Pry.history.clear
output.puts 'History cleared.'
end

Expand Down
2 changes: 1 addition & 1 deletion lib/pry/input_history.rb
@@ -1,5 +1,5 @@
class Pry
class InputHistory
class History
def initialize
@history = []
@first_new_line = 0 # TODO: rename this
Expand Down
10 changes: 5 additions & 5 deletions lib/pry/pry_class.rb
Expand Up @@ -38,8 +38,8 @@ def self.delegate_accessors(delagatee, *names)
# @return [OpenStruct] Return Pry's config object.
attr_accessor :config

# @return [InputHistory] TODO: put something here
attr_accessor :input_history
# @return [History] TODO: put something here
attr_accessor :history

# @return [Boolean] Whether Pry was activated from the command line.
attr_accessor :cli
Expand Down Expand Up @@ -126,12 +126,12 @@ def self.view_clip(obj, max_length = 60)

# Load Readline history if required.
def self.load_history
Pry.input_history.load(history_file) if File.exists?(history_file)
Pry.history.load(history_file) if File.exists?(history_file)
end

# Save new lines of Readline history if required.
def self.save_history
Pry.input_history.save(history_file)
Pry.history.save(history_file)
end

# Get the full path of the history_path for pry.
Expand Down Expand Up @@ -232,7 +232,7 @@ def self.reset_defaults
def self.init
@plugin_manager ||= PluginManager.new
self.config ||= Config.new
self.input_history ||= InputHistory.new
self.history ||= History.new

reset_defaults
locate_plugins
Expand Down
4 changes: 2 additions & 2 deletions lib/pry/pry_instance.rb
Expand Up @@ -154,7 +154,7 @@ def repl_epilogue(target, break_data)

Pry.active_sessions -= 1
binding_stack.pop
Pry.save_history if Pry.config.history.should_save && Pry.active_sessions == 0
Pry.history.save if Pry.config.history.should_save && Pry.active_sessions == 0
break_data
end

Expand Down Expand Up @@ -373,7 +373,7 @@ def readline(current_prompt="> ")

if input == Readline
line = input.readline(current_prompt, false)
Pry.input_history << line
Pry.history << line
line
else
begin
Expand Down
4 changes: 2 additions & 2 deletions test/test_default_commands/test_input.rb
Expand Up @@ -202,8 +202,8 @@ def $o.test_method
end

before do
Pry.input_history.clear
@hist = Pry.input_history
Pry.history.clear
@hist = Pry.history
end

it 'should display the correct history' do
Expand Down
26 changes: 13 additions & 13 deletions test/test_pry_history.rb
Expand Up @@ -4,7 +4,7 @@
describe Pry do

before do
Pry.input_history.clear
Pry.history.clear
@hist = Tempfile.new(["tmp", ".pry_history"]).tap(&:close).path
File.open(@hist, 'w') {|f| f << "1\n2\n3\n" }
@old_hist = Pry.config.history.file
Expand All @@ -19,13 +19,13 @@

describe ".load_history" do
it "should read the contents of the file" do
Pry.input_history.to_a[-2..-1].should === ["2", "3"]
Pry.history.to_a[-2..-1].should === ["2", "3"]
end
end

describe ".save_history" do
it "should include a trailing newline" do
Pry.input_history << "4"
Pry.history << "4"
Pry.save_history
File.read(@hist).should =~ /4\n\z/
end
Expand All @@ -37,45 +37,45 @@
end

it "should append new lines to the file" do
Pry.input_history << "4"
Pry.history << "4"
Pry.save_history
File.read(@hist).should == "1\n2\n3\n4\n"
end

it "should not clobber lines written by other Pry's in the meantime" do
Pry.input_history << "5"
Pry.history << "5"
File.open(@hist, 'a') {|f| f << "4\n" }
Pry.save_history

Pry.input_history.to_a[-3..-1].should == ["2", "3", "5"]
Pry.history.to_a[-3..-1].should == ["2", "3", "5"]
File.read(@hist).should == "1\n2\n3\n4\n5\n"
end

it "should not delete lines from the file if this session's history was cleared" do
Pry.input_history.clear
Pry.history.clear
Pry.save_history
File.read(@hist).should == "1\n2\n3\n"
end

it "should save new lines that are added after the history was cleared" do
Pry.input_history.clear
Pry.input_history << "4"
Pry.history.clear
Pry.history << "4"

# doing this twice as libedit on 1.8.7 has bugs and sometimes ignores the
# first line in history
Pry.input_history << "4"
Pry.history << "4"
Pry.save_history
File.read(@hist).should =~ /1\n2\n3\n4\n/
end

it "should only append new lines the second time it is saved" do
Pry.input_history << "4"
Pry.history << "4"
Pry.save_history
File.open(@hist, 'a') {|f| f << "5\n" }
Pry.input_history << "6"
Pry.history << "6"
Pry.save_history

Pry.input_history.to_a[-4..-1].should == ["2", "3", "4", "6"]
Pry.history.to_a[-4..-1].should == ["2", "3", "4", "6"]
File.read(@hist).should == "1\n2\n3\n4\n5\n6\n"
end
end
Expand Down

0 comments on commit a1a7cdc

Please sign in to comment.