Skip to content

Instantly share code, notes, and snippets.

@chrismcg
Created August 22, 2008 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismcg/6778 to your computer and use it in GitHub Desktop.
Save chrismcg/6778 to your computer and use it in GitHub Desktop.
# 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