diff options
author | Armin <mail@arminfroehlich.de> | 2021-07-01 09:21:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-01 10:21:14 +0300 |
commit | db856653dd47995c39711f1518ebf94792e9c471 (patch) | |
tree | e430ece5c16b62ea175345d521014460a6ba3b61 /lib | |
parent | 586e1bd1502983cf52d6fd76902224b5731816e9 (diff) | |
download | pry-db856653dd47995c39711f1518ebf94792e9c471.tar.gz |
validates file presence in Config#default_rc_file (#2129)
* validates file presence in Config#default_rc_file
Return `nil` if no default rc file is present in the filesystem.
This fixes the behavior if $XDG_CONFIG_HOME is set, but no rc file at
the path `$XDG_CONFIG_HOME/pry/pryrc` (while it may be at `~/.pryrc`).
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pry/config.rb | 19 | ||||
-rw-r--r-- | lib/pry/pry_class.rb | 2 |
2 files changed, 9 insertions, 12 deletions
diff --git a/lib/pry/config.rb b/lib/pry/config.rb index 48c4089d..0c6a0edc 100644 --- a/lib/pry/config.rb +++ b/lib/pry/config.rb @@ -301,17 +301,14 @@ class Pry end def default_rc_file - if (pryrc = Pry::Env['PRYRC']) - pryrc - elsif (xdg_home = Pry::Env['XDG_CONFIG_HOME']) - # See XDG Base Directory Specification at - # https://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html - xdg_home + '/pry/pryrc' - elsif File.exist?(File.expand_path('~/.pryrc')) - '~/.pryrc' - else - '~/.config/pry/pryrc' - end + [Pry::Env['PRYRC'], + # See XDG Base Directory Specification at + # https://specifications.freedesktop.org/basedir-spec/latest/ + "#{Pry::Env['XDG_CONFIG_HOME']}/pry/pryrc", + File.expand_path('~/.pryrc'), + File.expand_path('~/.config/pry/pryrc')] + .compact + .find { |file| File.exist?(file) } end end end diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb index 118102dd..651cf67e 100644 --- a/lib/pry/pry_class.rb +++ b/lib/pry/pry_class.rb @@ -85,7 +85,7 @@ class Pry # Load the local RC file (./.pryrc) def self.rc_files_to_load files = [] - files << Pry.config.rc_file if Pry.config.should_load_rc + 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 end |