Created
April 13, 2011 09:48
-
-
Save cpetschnig/917284 to your computer and use it in GitHub Desktop.
IRB customization: load wirble, looksee and awesome_print; cheat bundler
This file contains 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
require 'rubygems' | |
@irb_extensions = [] | |
def require_for_irb_with_fallback_for_bundler_constraints(gem_name, load_file = nil) | |
load_file ||= gem_name | |
begin | |
begin | |
require load_file | |
rescue LoadError => e | |
gem_paths = [] | |
Gem.path.each do |sys_gem_path| | |
Dir[sys_gem_path + '/gems/*'].each do |gem_path| | |
gem_paths << gem_path if %r{#{gem_name}} =~ gem_path | |
end | |
end | |
if gem_paths.empty? | |
error = LoadError.new("It seems like #{gem_name} is not installed.") | |
class << error; def skip_backtrace?; true; end; end | |
raise error | |
end | |
load_path = gem_paths.sort_by(&:to_s).last + "/lib/#{load_file}.rb" | |
load load_path | |
end | |
yield if block_given? | |
@irb_extensions << gem_name | |
rescue Exception => err | |
msg = "Couldn't load #{gem_name}: #{err}" | |
msg << "\n#{err.backtrace[0..10].join("\n")}" unless err.respond_to?(:skip_backtrace?) && err.skip_backtrace? | |
warn msg | |
end | |
end | |
require_for_irb_with_fallback_for_bundler_constraints 'wirble' do | |
# start wirble (with color) | |
Wirble.init | |
Wirble.colorize | |
end | |
require_for_irb_with_fallback_for_bundler_constraints 'looksee' do | |
Looksee.default_width = 160 | |
end | |
require_for_irb_with_fallback_for_bundler_constraints 'awesome_print', 'ap' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is awesome! Thanks so much for sharing.