mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Use Pry::Env where it makes sense
This commit is contained in:
parent
7ce5ca70bb
commit
6e55df5a0f
12 changed files with 56 additions and 50 deletions
|
@ -48,7 +48,7 @@ class Pry
|
||||||
end
|
end
|
||||||
|
|
||||||
def cd_path_env
|
def cd_path_env
|
||||||
ENV['CDPATH']
|
Pry::Env['CDPATH']
|
||||||
end
|
end
|
||||||
|
|
||||||
def cd_path_exists?
|
def cd_path_exists?
|
||||||
|
|
|
@ -305,12 +305,12 @@ class Pry
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_rc_file
|
def default_rc_file
|
||||||
if ENV.key?('PRYRC')
|
if (pryrc = Pry::Env['PRYRC'])
|
||||||
ENV['PRYRC']
|
pryrc
|
||||||
elsif ENV.key?('XDG_CONFIG_HOME') && ENV['XDG_CONFIG_HOME'] != ''
|
elsif (xdg_home = Pry::Env['XDG_CONFIG_HOME'])
|
||||||
# See XDG Base Directory Specification at
|
# See XDG Base Directory Specification at
|
||||||
# https://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html
|
# https://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html
|
||||||
ENV['XDG_CONFIG_HOME'] + '/pry/pryrc'
|
xdg_home + '/pry/pryrc'
|
||||||
elsif File.exist?(File.expand_path('~/.pryrc'))
|
elsif File.exist?(File.expand_path('~/.pryrc'))
|
||||||
'~/.pryrc'
|
'~/.pryrc'
|
||||||
else
|
else
|
||||||
|
|
|
@ -5,12 +5,18 @@ require 'shellwords'
|
||||||
class Pry
|
class Pry
|
||||||
class Editor
|
class Editor
|
||||||
def self.default
|
def self.default
|
||||||
return ENV['VISUAL'] if ENV['VISUAL'] && !ENV['VISUAL'].empty?
|
if (visual = Pry::Env['VISUAL'])
|
||||||
return ENV['EDITOR'] if ENV['EDITOR'] && !ENV['EDITOR'].empty?
|
return visual
|
||||||
|
end
|
||||||
|
|
||||||
|
if (editor = Pry::Env['EDITOR'])
|
||||||
|
return editor
|
||||||
|
end
|
||||||
|
|
||||||
return 'notepad' if Helpers::Platform.windows?
|
return 'notepad' if Helpers::Platform.windows?
|
||||||
|
|
||||||
%w[editor nano vi].find do |editor|
|
%w[editor nano vi].find do |editor_exe|
|
||||||
Kernel.system("which #{editor} > /dev/null 2>&1")
|
Kernel.system("which #{editor_exe} > /dev/null 2>&1")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,8 @@ class Pry
|
||||||
end
|
end
|
||||||
|
|
||||||
def use_ansi_codes?
|
def use_ansi_codes?
|
||||||
Pry::Helpers::Platform.windows_ansi? || ENV['TERM'] && ENV['TERM'] != "dumb"
|
Pry::Helpers::Platform.windows_ansi? ||
|
||||||
|
((term = Pry::Env['TERM']) && term != "dumb")
|
||||||
end
|
end
|
||||||
|
|
||||||
def colorize_code(code)
|
def colorize_code(code)
|
||||||
|
|
|
@ -28,7 +28,7 @@ class Pry
|
||||||
def self.windows_ansi?
|
def self.windows_ansi?
|
||||||
return false unless windows?
|
return false unless windows?
|
||||||
|
|
||||||
!!(defined?(Win32::Console) || ENV['ANSICON'] || mri_2?)
|
!!(defined?(Win32::Console) || Pry::Env['ANSICON'] || mri_2?)
|
||||||
end
|
end
|
||||||
|
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
|
|
|
@ -6,10 +6,10 @@ class Pry
|
||||||
class History
|
class History
|
||||||
def self.default_file
|
def self.default_file
|
||||||
history_file =
|
history_file =
|
||||||
if ENV.key?('XDG_DATA_HOME') && ENV['XDG_DATA_HOME'] != ''
|
if (xdg_home = Pry::Env['XDG_DATA_HOME'])
|
||||||
# See XDG Base Directory Specification at
|
# See XDG Base Directory Specification at
|
||||||
# https://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html
|
# https://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html
|
||||||
ENV['XDG_DATA_HOME'] + '/pry/pry_history'
|
xdg_home + '/pry/pry_history'
|
||||||
elsif File.exist?(File.expand_path('~/.pry_history'))
|
elsif File.exist?(File.expand_path('~/.pry_history'))
|
||||||
'~/.pry_history'
|
'~/.pry_history'
|
||||||
else
|
else
|
||||||
|
|
|
@ -107,7 +107,7 @@ class Pry
|
||||||
end
|
end
|
||||||
|
|
||||||
def env_size
|
def env_size
|
||||||
size = [ENV['LINES'] || ENV['ROWS'], ENV['COLUMNS']]
|
size = [Pry::Env['LINES'] || Pry::Env['ROWS'], Pry::Env['COLUMNS']]
|
||||||
size if nonzero_column?(size)
|
size if nonzero_column?(size)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ class Pry
|
||||||
end
|
end
|
||||||
|
|
||||||
def ansicon_env_size
|
def ansicon_env_size
|
||||||
return unless ENV['ANSICON'] =~ /\((.*)x(.*)\)/
|
return unless Pry::Env['ANSICON'] =~ /\((.*)x(.*)\)/
|
||||||
|
|
||||||
size = [Regexp.last_match(2), Regexp.last_match(1)]
|
size = [Regexp.last_match(2), Regexp.last_match(1)]
|
||||||
size if nonzero_column?(size)
|
size if nonzero_column?(size)
|
||||||
|
|
|
@ -128,7 +128,7 @@ class Pry
|
||||||
# buffered content.
|
# buffered content.
|
||||||
class SystemPager < NullPager
|
class SystemPager < NullPager
|
||||||
def self.default_pager
|
def self.default_pager
|
||||||
pager = ENV["PAGER"] || ""
|
pager = Pry::Env['PAGER'] || ''
|
||||||
|
|
||||||
# Default to less, and make sure less is being passed the correct
|
# Default to less, and make sure less is being passed the correct
|
||||||
# options
|
# options
|
||||||
|
|
|
@ -150,8 +150,8 @@ you can add "Pry.config.windows_console_warning = false" to your pryrc.
|
||||||
# @example
|
# @example
|
||||||
# Pry.start(Object.new, :input => MyInput.new)
|
# Pry.start(Object.new, :input => MyInput.new)
|
||||||
def self.start(target = nil, options = {})
|
def self.start(target = nil, options = {})
|
||||||
return if ENV['DISABLE_PRY']
|
return if Pry::Env['DISABLE_PRY']
|
||||||
if ENV['FAIL_PRY']
|
if Pry::Env['FAIL_PRY']
|
||||||
raise 'You have FAIL_PRY set to true, which results in Pry calls failing'
|
raise 'You have FAIL_PRY set to true, which results in Pry calls failing'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -46,8 +46,10 @@ RSpec.describe Pry::Config do
|
||||||
|
|
||||||
describe "#rc_file" do
|
describe "#rc_file" do
|
||||||
context "when $PRYRC env variable is set" do
|
context "when $PRYRC env variable is set" do
|
||||||
before { ENV['PRYRC'] = '/foo/pryrc' }
|
before do
|
||||||
after { ENV.delete('PRYRC') }
|
allow(Pry::Env).to receive(:[])
|
||||||
|
allow(Pry::Env).to receive(:[]).with('PRYRC').and_return('/foo/pryrc')
|
||||||
|
end
|
||||||
|
|
||||||
it "defaults to the value of PRYRC env variable" do
|
it "defaults to the value of PRYRC env variable" do
|
||||||
expect(subject.rc_file).to eq('/foo/pryrc')
|
expect(subject.rc_file).to eq('/foo/pryrc')
|
||||||
|
@ -67,29 +69,32 @@ RSpec.describe Pry::Config do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when $XDG_CONFIG_HOME is defined" do
|
context "when $XDG_CONFIG_HOME is defined" do
|
||||||
before { ENV['XDG_CONFIG_HOME'] = '/xdg_home' }
|
before do
|
||||||
after { ENV.delete('XDG_CONFIG_HOME') }
|
allow(Pry::Env).to receive(:[])
|
||||||
|
allow(Pry::Env).to receive(:[])
|
||||||
|
.with('XDG_CONFIG_HOME').and_return('/xdg_home')
|
||||||
|
|
||||||
context "when ~/.pryrc exists" do
|
allow(File).to receive(:exist?)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "and when ~/.pryrc exists" do
|
||||||
before do
|
before do
|
||||||
allow(File).to receive(:exist?)
|
allow(File).to receive(:exist?)
|
||||||
expect(File).to receive(:exist?)
|
|
||||||
.with(File.expand_path('~/.pryrc')).and_return(true)
|
.with(File.expand_path('~/.pryrc')).and_return(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "defaults $XDG_CONFIG_HOME/pry/pryrc" do
|
it "defaults to $XDG_CONFIG_HOME/pry/pryrc" do
|
||||||
expect(subject.rc_file).to eq('/xdg_home/pry/pryrc')
|
expect(subject.rc_file).to eq('/xdg_home/pry/pryrc')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when ~/.pryrc doesn't exist" do
|
context "and when ~/.pryrc doesn't exist" do
|
||||||
before do
|
before do
|
||||||
allow(File).to receive(:exist?)
|
allow(File).to receive(:exist?)
|
||||||
expect(File).to receive(:exist?)
|
|
||||||
.with(File.expand_path('~/.pryrc')).and_return(false)
|
.with(File.expand_path('~/.pryrc')).and_return(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "defaults $XDG_CONFIG_HOME/pry/pryrc" do
|
it "defaults to $XDG_CONFIG_HOME/pry/pryrc" do
|
||||||
expect(subject.rc_file).to eq('/xdg_home/pry/pryrc')
|
expect(subject.rc_file).to eq('/xdg_home/pry/pryrc')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -212,13 +212,13 @@ RSpec.describe Pry::Output do
|
||||||
before do
|
before do
|
||||||
skip("io/console doesn't support JRuby") if Pry::Helpers::Platform.jruby?
|
skip("io/console doesn't support JRuby") if Pry::Helpers::Platform.jruby?
|
||||||
expect(output).to receive(:tty?).and_return(false)
|
expect(output).to receive(:tty?).and_return(false)
|
||||||
allow(ENV).to receive(:[])
|
allow(Pry::Env).to receive(:[])
|
||||||
end
|
end
|
||||||
|
|
||||||
context "and ENV has size info in ROWS and COLUMNS" do
|
context "and ENV has size info in ROWS and COLUMNS" do
|
||||||
before do
|
before do
|
||||||
expect(ENV).to receive(:[]).with('ROWS').and_return(2)
|
expect(Pry::Env).to receive(:[]).with('ROWS').and_return(2)
|
||||||
expect(ENV).to receive(:[]).with('COLUMNS').and_return(2)
|
expect(Pry::Env).to receive(:[]).with('COLUMNS').and_return(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the ENV variable winsize" do
|
it "returns the ENV variable winsize" do
|
||||||
|
@ -228,8 +228,8 @@ RSpec.describe Pry::Output do
|
||||||
|
|
||||||
context "and ENV has size info in LINES and COLUMNS" do
|
context "and ENV has size info in LINES and COLUMNS" do
|
||||||
before do
|
before do
|
||||||
expect(ENV).to receive(:[]).with('LINES').and_return(3)
|
expect(Pry::Env).to receive(:[]).with('LINES').and_return(3)
|
||||||
expect(ENV).to receive(:[]).with('COLUMNS').and_return(2)
|
expect(Pry::Env).to receive(:[]).with('COLUMNS').and_return(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns ENV variable winsize" do
|
it "returns ENV variable winsize" do
|
||||||
|
@ -246,7 +246,7 @@ RSpec.describe Pry::Output do
|
||||||
expect(output).to receive(:tty?).and_return(false)
|
expect(output).to receive(:tty?).and_return(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
allow(ENV).to receive(:[])
|
allow(Pry::Env).to receive(:[])
|
||||||
|
|
||||||
stub_const('Readline', readline)
|
stub_const('Readline', readline)
|
||||||
end
|
end
|
||||||
|
@ -280,7 +280,7 @@ RSpec.describe Pry::Output do
|
||||||
expect(output).to receive(:tty?).and_return(false)
|
expect(output).to receive(:tty?).and_return(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
allow(ENV).to receive(:[])
|
allow(Pry::Env).to receive(:[])
|
||||||
stub_const('Readline', readline)
|
stub_const('Readline', readline)
|
||||||
expect(readline).to receive(:respond_to?)
|
expect(readline).to receive(:respond_to?)
|
||||||
.with(:get_screen_size).and_return(false)
|
.with(:get_screen_size).and_return(false)
|
||||||
|
@ -290,7 +290,7 @@ RSpec.describe Pry::Output do
|
||||||
context "and when it can be matched" do
|
context "and when it can be matched" do
|
||||||
context "and when the size consists of positive integers" do
|
context "and when the size consists of positive integers" do
|
||||||
before do
|
before do
|
||||||
expect(ENV).to receive(:[]).with('ANSICON').and_return('(5x5)')
|
expect(Pry::Env).to receive(:[]).with('ANSICON').and_return('(5x5)')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the ansicon winsize" do
|
it "returns the ansicon winsize" do
|
||||||
|
@ -300,7 +300,7 @@ RSpec.describe Pry::Output do
|
||||||
|
|
||||||
context "and when the size has a zero column" do
|
context "and when the size has a zero column" do
|
||||||
before do
|
before do
|
||||||
expect(ENV).to receive(:[]).with('ANSICON').and_return('(0x0)')
|
expect(Pry::Env).to receive(:[]).with('ANSICON').and_return('(0x0)')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the default winsize" do
|
it "returns the default winsize" do
|
||||||
|
@ -311,7 +311,7 @@ RSpec.describe Pry::Output do
|
||||||
|
|
||||||
context "and when it cannot be matched" do
|
context "and when it cannot be matched" do
|
||||||
before do
|
before do
|
||||||
expect(ENV).to receive(:[]).with('ANSICON').and_return('5x5')
|
expect(Pry::Env).to receive(:[]).with('ANSICON').and_return('5x5')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the default winsize" do
|
it "returns the default winsize" do
|
||||||
|
@ -336,7 +336,7 @@ RSpec.describe Pry::Output do
|
||||||
expect(output).to receive(:tty?).and_return(false)
|
expect(output).to receive(:tty?).and_return(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
allow(ENV).to receive(:[])
|
allow(Pry::Env).to receive(:[])
|
||||||
stub_const('Readline', readline)
|
stub_const('Readline', readline)
|
||||||
expect(readline).to receive(:respond_to?)
|
expect(readline).to receive(:respond_to?)
|
||||||
.with(:get_screen_size).and_return(false)
|
.with(:get_screen_size).and_return(false)
|
||||||
|
@ -355,7 +355,7 @@ RSpec.describe Pry::Output do
|
||||||
expect(output).to receive(:tty?).and_return(false)
|
expect(output).to receive(:tty?).and_return(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
allow(ENV).to receive(:[])
|
allow(Pry::Env).to receive(:[])
|
||||||
stub_const('Readline', readline)
|
stub_const('Readline', readline)
|
||||||
expect(readline).to receive(:respond_to?)
|
expect(readline).to receive(:respond_to?)
|
||||||
.with(:get_screen_size).and_return(false)
|
.with(:get_screen_size).and_return(false)
|
||||||
|
|
|
@ -26,11 +26,8 @@ describe Pry do
|
||||||
|
|
||||||
describe 'DISABLE_PRY' do
|
describe 'DISABLE_PRY' do
|
||||||
before do
|
before do
|
||||||
ENV['DISABLE_PRY'] = 'true'
|
allow(Pry::Env).to receive(:[])
|
||||||
end
|
allow(Pry::Env).to receive(:[]).with('DISABLE_PRY').and_return(true)
|
||||||
|
|
||||||
after do
|
|
||||||
ENV.delete 'DISABLE_PRY'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not binding.pry' do
|
it 'should not binding.pry' do
|
||||||
|
@ -44,11 +41,8 @@ describe Pry do
|
||||||
|
|
||||||
describe 'FAIL_PRY' do
|
describe 'FAIL_PRY' do
|
||||||
before do
|
before do
|
||||||
ENV['FAIL_PRY'] = 'true'
|
allow(Pry::Env).to receive(:[])
|
||||||
end
|
allow(Pry::Env).to receive(:[]).with('FAIL_PRY').and_return(true)
|
||||||
|
|
||||||
after do
|
|
||||||
ENV.delete 'FAIL_PRY'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should raise an error for binding.pry' do
|
it 'should raise an error for binding.pry' do
|
||||||
|
|
Loading…
Reference in a new issue