-
Notifications
You must be signed in to change notification settings - Fork 0
/
irbrc
executable file
·73 lines (62 loc) · 1.55 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
require 'rubygems'
require 'irb/completion'
require 'irb/ext/save-history'
warn "Loading custom irbrc"
begin
require 'interactive_editor'
rescue
warn "=> Unable to load interactive_editor"
end
begin
require 'hirb'
Hirb.enable
extend Hirb::Console
module DatabaseHelpers
extend self
def tables
Hirb::Console.render_output ActiveRecord::Base.connection.tables.map{|e|[e]},{
:class => Hirb::Helpers::AutoTable,
:headers => %w<tables>,
}
true
end
def table(which)
Hirb::Console.render_output ActiveRecord::Base.connection.columns(which).map{ |e|
[e.name, e.type, e.sql_type, e.limit, e.default, e.scale, e.precision, e.primary, e.null]
},{
:class => Hirb::Helpers::AutoTable,
:headers => %w<name type sql_type limit default scale precision primary null>,
}
true
end
def counts
Hirb::Console.render_output ActiveRecord::Base.connection.tables.map{|e|
[e, ActiveRecord::Base.connection.select_value("SELECT COUNT(*) FROM #{e}")]
},{
:class => Hirb::Helpers::AutoTable,
:headers => %w<table count>,
}
true
end
# ...
end
rescue
warn "=> Unable to load hirb"
end
begin
require 'awesome_print'
rescue
warn "=> Unable to load awesome_print"
end
class Object
# Return only the methods not present on basic objects
def interesting_methods
(self.methods - Object.new.methods).sort
end
end
def db
DatabaseHelpers
end
def sql(query)
ActiveRecord::Base.connection.select_all(query)
end