Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
85 lines (76 sloc) 2.21 KB
if (rails_env = ENV['RAILS_ENV']) || (rails_env = Rails.env)
rails_root = File.basename(Dir.pwd)
rails_env_string = case rails_env
when 'development'
'[DEV]'
when 'production'
'[PROD]'
else
"[#{rails_env.upcase}]"
end
# script/console prompt
IRB.conf[:PROMPT] ||= {}
IRB.conf[:PROMPT][:RAILS] = {
:PROMPT_I => "#{rails_root} #{rails_env_string}>> ",
:PROMPT_S => "#{rails_root} #{rails_env_string}* ",
:PROMPT_C => "#{rails_root} #{rails_env_string}? ",
:RETURN => "=> %s\n"
}
IRB.conf[:PROMPT_MODE] = :RAILS
# Called after the irb session is initialized and Rails has been loaded
IRB.conf[:IRB_RC] = Proc.new do
# [] acts as find()
ActiveRecord::Base.instance_eval { alias :[] :find }
def r!
reload!
end
# sql for arbitrary SQL commands through the AR
def sql(query)
ActiveRecord::Base.connection.execute(query)
end
end
end
# set logging to screen
if ENV.include?('RAILS_ENV')
# Rails 2.x
if !Object.const_defined?('RAILS_DEFAULT_LOGGER')
require 'logger'
Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(STDOUT))
end
else
# Rails 3
if Rails.logger
Rails.logger = Logger.new(STDOUT)
ActiveRecord::Base.logger = Rails.logger
end
end
# .details method for pretty printing ActiveRecord's objects attributes
class Object
def details
if self.respond_to?(:attributes) and self.attributes.any?
max = self.attributes.keys.sort_by { |k| k.size }.pop.size + 5
puts
self.attributes.keys.sort.each do |k|
puts sprintf("%-#{max}.#{max}s%s", k, self.try(k))
end
puts
end
end
alias :detailed :details
end
# readable BigDecimal#inspect output (https://gist.github.com/henrik/6280438)
# for Ruby 1.9+ and Rails 3+
if RUBY_VERSION >= '1.9.0' && defined?(Rails)
class BigDecimal
def inspect
format("#<BigDecimal:%x %s>", object_id, to_s('F'))
end
end
end
# returns a collection of the methods that Rails added to the given class
# http://lucapette.com/irb/rails-core-ext-and-irb/
class Class
def core_ext
self.instance_methods.map {|m| [m, self.instance_method(m).source_location] }.select {|m| m[1] && m[1][0] =~/activesupport/}.map {|m| m[0]}.sort
end
end
You can’t perform that action at this time.