Created
August 22, 2008 10:09
-
-
Save chrismcg/6778 to your computer and use it in GitHub Desktop.
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
# in ~/.irbrc | |
if ENV['RAILS_ENV'] | |
load '~/.railsrc' | |
end | |
# in ~/.railsrc | |
def sql(query) | |
ActiveRecord::Base.connection.select_all(query) | |
end | |
def loud_logger | |
set_logger_to Logger.new(STDOUT) | |
end | |
def quiet_logger | |
set_logger_to nil | |
end | |
def set_logger_to(logger) | |
ActiveRecord::Base.logger = logger | |
ActiveRecord::Base.clear_active_connections! | |
end | |
if ENV['LOG_TO_STDOUT'] | |
require 'logger' | |
Object.const_set(:RAILS_DEFAULT_LOGGER, Logger.new(STDOUT)) | |
end | |
def define_model_find_shortcuts | |
model_files = Dir.glob("app/models/**/*.rb") | |
table_names = model_files.map { |f| File.basename(f).split('.')[0..-2].join } | |
table_names.each do |table_name| | |
Object.instance_eval do | |
define_method(table_name) do |*args| | |
table_name.camelize.constantize.send(:find, *args) | |
end | |
end | |
end | |
end | |
IRB.conf[:IRB_RC] = Proc.new { define_model_find_shortcuts } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment