Posted By

ctran on 02/20/08


Tagged

rails irb


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

webstic


My .railsrc


 / Published in: Ruby
 

My .railsrc

  1. require 'logger'
  2. Object.const_set(:RAILS_DEFAULT_LOGGER, Logger.new(STDOUT))
  3.  
  4. def sql(query)
  5. ActiveRecord::Base.connection.select_all(query)
  6. end
  7.  
  8. def loud_logger
  9. set_logger_to Logger.new(STDOUT)
  10. end
  11.  
  12. def quiet_logger
  13. set_logger_to nil
  14. end
  15.  
  16. def set_logger_to(logger)
  17. ActiveRecord::Base.logger = logger
  18. ActiveRecord::Base.clear_active_connections!
  19. end
  20.  
  21. def define_model_find_shortcuts
  22. model_files = Dir.glob("app/models/**/*.rb" )
  23. table_names = model_files.map { |f| File.basename(f).split('.' )[0..-2].join }
  24. table_names.each do |table_name|
  25. Object.instance_eval do
  26. define_method(table_name) do |*args|
  27. table_name.camelize.constantize.send(:find, *args)
  28. end
  29. end
  30. end
  31. end
  32.  
  33. IRB.conf[:IRB_RC] = Proc.new { define_model_find_shortcuts }

Report this snippet  

You need to login to post a comment.