Created
May 9, 2011 18:47
-
-
Save rcreasey/963107 to your computer and use it in GitHub Desktop.
irbrc
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
| require 'irb/completion' | |
| require 'irb/ext/save-history' | |
| require 'map_by_method' | |
| require 'what_methods' | |
| require 'pp' | |
| require 'hirb' | |
| require 'wirble' | |
| require 'ap' | |
| Wirble.init | |
| Wirble.colorize | |
| Hirb.enable | |
| IRB.conf[:SAVE_HISTORY] = 100 | |
| IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history" | |
| IRB.conf[:PROMPT_MODE] = :SIMPLE | |
| IRB.conf[:AUTO_INDENT]=true | |
| # Just for Rails... | |
| if rails_env = ENV['RAILS_ENV'] | |
| rails_root = File.basename(Dir.pwd) | |
| IRB.conf[:PROMPT] ||= {} | |
| IRB.conf[:PROMPT][:RAILS] = { | |
| :PROMPT_I => "#{rails_root}> ", | |
| :PROMPT_S => "#{rails_root}* ", | |
| :PROMPT_C => "#{rails_root}? ", | |
| :RETURN => "=> %s\n" | |
| } | |
| IRB.conf[:PROMPT_MODE] = :RAILS | |
| IRB.conf[:IRB_RC] = Proc.new do | |
| ActiveRecord::Base.logger = Logger.new(STDOUT) | |
| ActiveRecord::Base.instance_eval { alias :[] :find } | |
| end | |
| end | |
| # In irb, can type: | |
| # people/6 instead of Person.find(6) | |
| # That is, can paste in urls into irb to find objects. | |
| class ModelProxy | |
| def initialize(klass) | |
| @klass = klass | |
| end | |
| def /(id) | |
| @klass.find(id) | |
| end | |
| end | |
| def define_model_find_shortcuts | |
| model_files = Dir.glob("app/models/**/*.rb") | |
| model_names = model_files.map { |f| File.basename(f).split('.')[0..-2].join } | |
| model_names.each do |model_name| | |
| Object.instance_eval do | |
| define_method(model_name.pluralize) do |*args| | |
| ModelProxy.new(model_name.camelize.constantize) | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment