forked from NIA/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
irbrc
87 lines (65 loc) · 1.56 KB
/
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
78
79
80
81
82
83
84
85
86
87
# Put this content to ~/.irbrc file (no extension)
require "rubygems"
begin
require "ap"
rescue LoadError => err
puts "Cannot find awesome_print gem. Please run 'gem install awesome_print' to install it."
end
begin
require "wirble"
Wirble::Colorize.colors.merge!(
:object_class => :black,
:class => :dark_gray,
:symbol => :red,
:symbol_prefix=> :blue
)
Wirble.init
Wirble.colorize
rescue LoadError => err
puts "Cannot find wirble. Please run 'gem install wirble' to install it."
end
begin
require 'looksee'
Looksee.styles.merge!(
:module => "\e[1;34m%s\e[0m" # purple
)
rescue LoadError
puts "Cannot find looksee. Please run 'gem install looksee' to install it."
end
# Rails on-screen logging
def change_log(stream)
ActiveRecord::Base.logger = Logger.new(stream)
ActiveRecord::Base.clear_active_connections!
end
def show_log
change_log(STDOUT)
puts "SQL log enabled. Enter 'reload!' to reload all loaded ActiveRecord classes"
end
def hide_log
change_log(nil)
puts "SQL log disabled. Enter 'reload!' to reload all loaded ActiveRecord classes"
end
# Simple benchmarking
def time(times = 1)
require 'benchmark'
ret = nil
Benchmark.bm { |x| x.report { times.times { ret = yield } } }
ret
end
# IRB configuration reloading
def IRB.reload
load __FILE__
end
# SQL query execution
def sql(query)
ActiveRecord::Base.connection.select_all(query)
end
# Hirb
if ENV['RAILS_ENV']
begin
require 'hirb'
Hirb.enable
rescue LoadError
puts "Error loading Hirb. Run 'sudo gem install hirb'"
end
end