Skip to content

Instantly share code, notes, and snippets.

@jbailey
Created August 30, 2012 17:54
Show Gist options
  • Save jbailey/3535448 to your computer and use it in GitHub Desktop.
Save jbailey/3535448 to your computer and use it in GitHub Desktop.
Railsrc file
In your .irbrc file put:
load File.dirname(__FILE__) + '/.railsrc' if ($0 == 'irb' && ENV['RAILS_ENV']) || ($0 == 'script/rails' && Rails.env)
This is the .railsrc file
#!/usr/bin/ruby
begin
require 'hirb' # sudo gem install cldwalker-hirb --source http://gems.github.com
Hirb.enable
rescue LoadError
end
def change_log(stream)
ActiveRecord::Base.logger = Logger.new(stream)
ActiveRecord::Base.clear_active_connections!
end
def show_log
change_log(STDOUT)
true
end
def hide_log
change_log(nil)
true
end
def load_lib
path = File.join( Rails.root, 'lib')
failures = []
Dir.glob("#{path}/**/*.rb").each { |file|
#puts "loading: #{file} ... "
begin
load file
rescue => ex
failures << file
end
}
# this second pass is here to try to catch anything that
# is dependent on something else
# could be improved, but is working fine for my needs
double_failures = []
for file in failures
begin
load file
rescue => ex1
double_failures << file
end
end
if double_failures.size > 0
puts "these files failed twice"
for file in double_failures
puts file
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment