class Bazinga::Runner

Constants

COLOR_MAP

Public Class Methods

colorize(text, color) click to toggle source

Issue: readline breaks. Fixed. Credits: stackoverflow.com/questions/8806643/colorized-output-breaks-linewrapping-with-readline

# File lib/bazinga/bazinga-conf.rb, line 14
def colorize(text, color)
  "#{COLOR_MAP[color]}#{text}#{COLOR_MAP['reset']}"
end
run() click to toggle source
# File lib/bazinga/bazinga-conf.rb, line 18
def run
  env_tag = (ENV['RAILS_ENV'] && ENV['RAILS_ENV'].downcase) || (Rails && Rails.env && Rails.env.downcase)

  app_name =
      ENV['BAZINGA_APP_NAME'] ||
          (Bazinga::APP_NAME rescue nil) ||
          Rails.application.class.parent_name.underscore.gsub("_", "-")

  console_tag = case env_tag
                  when 'production' then "(#{colorize('prod', 'red')})"
                  when 'staging' then "(#{colorize('staging', 'yellow')})"
                  when 'development' then "(#{colorize('dev', 'green')})"
                  else "(#{colorize(env_tag, 'yellow')})"
                end

  IRB.conf[:PROMPT][:RAILS_ENV] = {
      :PROMPT_I => "#{app_name}#{console_tag} :%03n > ",
      :PROMPT_N => "#{app_name}#{console_tag} :%03n?> ",
      :PROMPT_S => "",
      :PROMPT_C => "#{app_name}#{console_tag} :%03n?> ",
      :RETURN => "=> %s\n"
  }

  IRB.conf[:PROMPT_MODE] = :RAILS_ENV
  puts "#{COLOR_MAP['red']}Logged in on Production#{COLOR_MAP['reset']}" if env_tag.eql? 'production'
end