Created
May 16, 2011 23:49
-
-
Save mkdynamic/975617 to your computer and use it in GitHub Desktop.
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
# Time loading files | |
if ENV["TIMING"] == "1" | |
require 'benchmark' | |
module Kernel | |
class << self | |
def require_with_timing(file) | |
puts Benchmark.measure("require #{file}") { | |
require_without_timing(file) | |
}.format("%n: %t %r") | |
end | |
alias_method :require_without_timing, :require | |
alias_method :require, :require_with_timing | |
end | |
end | |
end | |
# Simple prompt mode | |
IRB.conf[:PROMPT_MODE] = :SIMPLE | |
# Automatic indentation | |
IRB.conf[:AUTO_INDENT] = true | |
# Load in gems, accounting for bundler | |
require 'rubygems' unless defined? Gem # rubygems is only needed in 1.8 | |
require 'pp' | |
require 'irb/completion' | |
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, "coudln'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 | |
# Highlighting and other features | |
load_gem 'wirble' do | |
Wirble.init | |
Wirble.colorize | |
end | |
# Improved formatting for objects | |
load_gem 'awesome_print' | |
# # Improved formatting for collections | |
# load_gem 'hirb' do | |
# Hirb.enable | |
# end | |
# Show log in Rails console | |
if defined? Rails | |
require 'logger' | |
if ENV['SC_LOG'] = 'true' | |
logger = Logger.new(STDOUT) | |
if Rails.version =~ /^2\./ # Rails 2.3 | |
Object.const_set('RAILS_DEFAULT_LOGGER', logger) | |
else # Rails 3 | |
Rails.logger = logger | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment