-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrailsrc
88 lines (78 loc) · 2.2 KB
/
railsrc
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
88
Hirb.enable
# # #
# misc db helpers (requires hirb)
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
def db; DatabaseHelpers; end
# # #
# route list view helpers (requires hirb)
# hirb view for a route
class Hirb::Helpers::Route < Hirb::Helpers::AutoTable
def self.render(output, options = {})
super( output.requirements.map{ |k,v|
[k, v.inspect]
}, options.merge({
:headers => [output.name || '', "#{ output.verb || 'ANY' } #{ output.path }"],
:unicode => true,
:description => nil,
}) )
end
end
Hirb.add_view ActionDispatch::Routing::Route, :class => Hirb::Helpers::Route
# short and long route list
def routes(long_output = false)
if long_output
Rails.application.routes.routes.each{ |e|
puts Hirb::Helpers::Route.render(e)
}
true
else
Hirb::Console.render_output Rails.application.routes.routes.map{|e|
[e.name || '', e.verb || 'ANY', e.path]
},{
:class => Hirb::Helpers::AutoTable,
:headers => %w<name verb path>,
}
end
end
# # #
# rails prompt
#app_name = Rails.application.class.parent_name.downcase
app_env = Rails.env[0...3]
IRB.conf[:PROMPT] ||= {}
IRB.conf[:PROMPT][:RAILS] = {
:PROMPT_I => "#{ app_env } > ",
:PROMPT_N => "#{ app_env } | ",
:PROMPT_C => "#{ app_env } | ",
:PROMPT_S => "#{ app_env } %l ",
:RETURN => "=> %s\n",
:AUTO_INDENT => true,
}
IRB.conf[:PROMPT_MODE] = :RAILS