mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Ignore -n and disable_auto_reload in tempfile cases
This commit is contained in:
parent
b460170039
commit
46288ab002
2 changed files with 20 additions and 13 deletions
|
@ -30,7 +30,7 @@ class Pry
|
|||
opt.on :t, :temp, "Open an empty temporary file"
|
||||
opt.on :l, :line, "Jump to this line in the opened file",
|
||||
:argument => true, :as => Integer
|
||||
opt.on :n, :"no-reload", "Don't automatically reload the edited code"
|
||||
opt.on :n, :"no-reload", "Don't automatically reload the edited file"
|
||||
opt.on :c, :current, "Open the current __FILE__ and at __LINE__ (as returned by `whereami`)"
|
||||
opt.on :r, :reload, "Reload the edited code immediately (default for ruby files)"
|
||||
opt.on :p, :patch, "Instead of editing the object's file, try to edit in a tempfile and apply as a monkey patch"
|
||||
|
@ -62,12 +62,10 @@ class Pry
|
|||
def repl_edit
|
||||
content = Pry::Editor.edit_tempfile_with_content(initial_temp_file_content,
|
||||
initial_temp_file_content.lines.count)
|
||||
if repl_reload?
|
||||
silence_warnings do
|
||||
eval_string.replace content
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def file_based_exception?
|
||||
opts.present?(:ex) && !opts.present?(:patch)
|
||||
|
@ -170,11 +168,6 @@ class Pry
|
|||
opts.present?(:'no-reload') || Pry.config.disable_auto_reload
|
||||
end
|
||||
|
||||
# conditions much less strict than for reload? (which is for file-based reloads)
|
||||
def repl_reload?
|
||||
!never_reload?
|
||||
end
|
||||
|
||||
def reload?(file_name="")
|
||||
(reloadable? || file_name.end_with?(".rb")) && !never_reload?
|
||||
end
|
||||
|
|
|
@ -338,13 +338,27 @@ describe "edit" do
|
|||
@t.eval_string.should == "'FOO'\n"
|
||||
end
|
||||
|
||||
it "should not evaluate the expression with -n" do
|
||||
it "should ignore -n for tempfiles" do
|
||||
Pry.config.editor = lambda {|file, line|
|
||||
File.open(file, 'w'){|f| f << "'FOO'\n" }
|
||||
nil
|
||||
}
|
||||
@t.process_command 'edit -n'
|
||||
@t.process_command "edit -n"
|
||||
@t.eval_string.should == "'FOO'\n"
|
||||
end
|
||||
|
||||
it "should not evaluate a file with -n" do
|
||||
Pry.config.editor = lambda {|file, line|
|
||||
File.open(file, 'w'){|f| f << "'FOO'\n" }
|
||||
nil
|
||||
}
|
||||
begin
|
||||
@t.process_command 'edit -n spec/fixtures/foo.rb'
|
||||
File.read("spec/fixtures/foo.rb").should == "'FOO'\n"
|
||||
@t.eval_string.should == ''
|
||||
ensure
|
||||
FileUtils.rm "spec/fixtures/foo.rb"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue