Created
June 17, 2014 17:54
-
-
Save edgar/ec767128eaa984a919c6 to your computer and use it in GitHub Desktop.
.pryrc file to customize Pry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pry.config.editor = 'subl3 -n -w' | |
require 'rubygems' unless defined? Gem # rubygems is only needed in 1.8 | |
def unbundled_require(gem) | |
loaded = false | |
if defined?(::Bundler) | |
Gem.path.each do |gems_path| | |
gem_path = Dir.glob("#{gems_path}/gems/#{gem}*").last | |
unless gem_path.nil? | |
$LOAD_PATH << "#{gem_path}/lib" | |
require gem | |
loaded = true | |
end | |
end | |
else | |
require gem | |
loaded = true | |
end | |
raise(LoadError, "couldn't find #{gem}") unless loaded | |
loaded | |
end | |
def load_gem(gem, &block) | |
begin | |
if unbundled_require gem | |
yield if block_given? | |
end | |
rescue Exception => err | |
warn "Couldn't load #{gem}: #{err}" | |
end | |
end | |
# Improved formatting for objects | |
load_gem 'awesome_print' do | |
# Pry.config.print = proc { |output, value| output.puts value.ai(:indent => 2) } | |
end | |
# for rails 2 | |
if ENV.include?('RAILS_ENV') | |
if !Object.const_defined?('RAILS_DEFAULT_LOGGER') | |
require 'logger' | |
Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(STDOUT)) | |
end | |
# for rails > 3 | |
elsif defined?(Rails) && !Rails.env.nil? | |
if Rails.logger | |
Rails.logger =Logger.new(STDOUT) | |
ActiveRecord::Base.logger = Rails.logger | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment