-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdot_irbrc
78 lines (66 loc) · 1.67 KB
/
dot_irbrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
if defined?(::Bundler)
global_path = File.expand_path('../../lib/ruby/gems/1.9.1/gems', `rbenv which ruby`.chomp)
[:wirble, :awesome_print].each do |gem|
path = Dir.glob("#{global_path}/*").grep(Regexp.new(gem.to_s)).first
if path && !path.empty?
$LOAD_PATH << "#{path}/lib"
elsif ENV['GEM_HOME']
# fall back to gem home
home = Dir.glob("#{ENV['GEM_HOME']}/*").grep(Regexp.new(gem.to_s)).first
if home
$LOAD_PATH << "#{home}/lib"
end
end
end
end
require 'rubygems' rescue nil
require 'wirble' rescue nil
require 'awesome_print' rescue nil
# load wirble
Wirble.init
Wirble.colorize
unless IRB.version.include?('DietRB')
IRB::Irb.class_eval do
def output_value
ap @context.last_value
end
end
else # MacRuby
IRB.formatter = Class.new(IRB::Formatter) do
def inspect_object(object)
object.ai
end
end.new
end
# load hirb
# IRB.conf[:AUTO_INDENT] = true
if ENV.include?('RAILS_ENV')
if !Object.const_defined?('RAILS_DEFAULT_LOGGER')
require 'logger'
Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(STDOUT))
end
def sql(query)
ActiveRecord::Base.connection.select_all(query)
end
if ENV['RAILS_ENV'] == 'test'
require 'test/test_helper'
end
# for rails 3
elsif defined?(Rails) && !Rails.env.nil? && defined?(ActiveRecord)
if Rails.logger
Rails.logger =Logger.new(STDOUT)
ActiveRecord::Base.logger = Rails.logger
end
if Rails.env == 'test'
require 'test/test_helper'
end
else
# nothing to do
end
if defined?(Mongoid)
Mongoid.config.logger = Logger.new($stdout)
end
# annotate column names of an AR model
def show(obj)
y(obj.send("column_names"))
end