Created
July 19, 2012 02:54
-
-
Save arches/3140457 to your computer and use it in GitHub Desktop.
Run a project-specific IRB config in Rails 3.1+
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
if ENV['RAILS_ENV'] | |
rails_env = ENV['RAILS_ENV'].downcase | |
elsif Rails and Rails.env | |
rails_env = Rails.env.downcase | |
end | |
if rails_env | |
current_app = "myapp" | |
black = "\[\033[0;30m\]" | |
red = "\[\033[0;31m\]" | |
green = "\[\033[0;32m\]" | |
yellow = "\[\033[0;33m\]" | |
blue = "\[\033[0;34m\]" | |
purple = "\[\033[0;35m\]" | |
cyan = "\[\033[0;36m\]" | |
reset = "\[\033[0;0m\]" | |
environment_color = case rails_env | |
when 'development' | |
green | |
when 'staging' | |
yellow | |
when 'production' | |
red | |
else | |
red | |
end | |
rails_env = {'development' => 'dev', 'staging' => 'staging', 'production' => 'prod'}.fetch(rails_env) { 'unknown' } | |
IRB.conf[:PROMPT][:RAILS_ENV] = { | |
:PROMPT_I => "#{green}#{current_app}#{environment_color}(#{rails_env})#{reset}> ", | |
:PROMPT_N => "#{green}#{current_app}#{environment_color}(#{rails_env})#{reset}> ", | |
:PROMPT_S => nil, | |
:PROMPT_C => "?> ", | |
:RETURN => "=> %s\n" | |
} | |
IRB.conf[:PROMPT_MODE] = :RAILS_ENV | |
end |
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
# Works on Heroku! | |
module MyAppName | |
class Application < Rails::Application | |
def load_console(app=self) | |
super | |
ARGV.push "-r", File.join(Rails.root, ".irbrc.rb") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm on it.. :)