Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Honor Pry.config.should_load_local_rc = false in global RC file #2243

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 18 additions & 10 deletions lib/pry/pry_class.rb
Expand Up @@ -75,19 +75,27 @@ def self.load_file_at_toplevel(file)
# Load RC files if appropriate This method can also be used to reload the
# files if they have changed.
def self.load_rc_files
rc_files_to_load.each do |file|
critical_section do
load_file_at_toplevel(file)
end
rc_files_loaded.clear
load_rc_file(Pry.config.rc_file) if Pry.config.rc_file && Pry.config.should_load_rc
load_rc_file(LOCAL_RC_FILE) if Pry.config.should_load_local_rc
end

def self.load_rc_file(file)
file = real_path_to(file)
return if file.nil?
return if rc_files_loaded.include?(file)

critical_section do
load_file_at_toplevel(file)
end

rc_files_loaded << file
end
private_class_method :load_rc_file

# Load the local RC file (./.pryrc)
def self.rc_files_to_load
files = []
files << Pry.config.rc_file if Pry.config.rc_file && Pry.config.should_load_rc
files << LOCAL_RC_FILE if Pry.config.should_load_local_rc
files.map { |file| real_path_to(file) }.compact.uniq
# @return [Array<String>] the files that have been loaded by {.load_rc_files}
def self.rc_files_loaded
@rc_files_loaded ||= []
end

# Expand a file to its canonical name (following symlinks as appropriate)
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/globalrc
@@ -0,0 +1,2 @@
LOADED_LOCAL_RC = false
Pry.config.should_load_local_rc = false
1 change: 1 addition & 0 deletions spec/fixtures/localrc
@@ -0,0 +1 @@
LOADED_LOCAL_RC = true
10 changes: 10 additions & 0 deletions spec/pryrc_spec.rb
Expand Up @@ -66,6 +66,16 @@
expect(Object.const_defined?(:TEST_RC)).to eq false
end

it "should not load the local rc if the global rc disables it" do
Pry.config.rc_file = 'spec/fixtures/globalrc'
stub_const('Pry::LOCAL_RC_FILE', 'spec/fixtures/localrc')
Pry.config.should_load_rc = true
Pry.config.should_load_local_rc = true
Pry.start(self, input: StringIO.new("exit-all\n"), output: StringIO.new)
expect(LOADED_LOCAL_RC).to be false
Object.remove_const(:LOADED_LOCAL_RC)
end

describe "that raise exceptions" do
before do
Pry.config.rc_file = 'spec/fixtures/testrcbad'
Expand Down