Froze rails gems
[depot.git] / vendor / rails / railties / builtin / rails_info / rails / info.rb
1 module Rails
2 module Info
3 mattr_accessor :properties
4 class << (@@properties = [])
5 def names
6 map &:first
7 end
8
9 def value_for(property_name)
10 if property = assoc(property_name)
11 property.last
12 end
13 end
14 end
15
16 class << self #:nodoc:
17 def property(name, value = nil)
18 value ||= yield
19 properties << [name, value] if value
20 rescue Exception
21 end
22
23 def components
24 %w( active_record action_pack active_resource action_mailer active_support )
25 end
26
27 def component_version(component)
28 require "#{component}/version"
29 "#{component.classify}::VERSION::STRING".constantize
30 end
31
32 def edge_rails_revision(info = git_info)
33 info[/commit ([a-z0-9-]+)/, 1] || freeze_edge_version
34 end
35
36 def freeze_edge_version
37 if File.exist?(rails_vendor_root)
38 begin
39 Dir[File.join(rails_vendor_root, 'REVISION_*')].first.scan(/_(\d+)$/).first.first
40 rescue
41 Dir[File.join(rails_vendor_root, 'TAG_*')].first.scan(/_(.+)$/).first.first rescue 'unknown'
42 end
43 end
44 end
45
46 def to_s
47 column_width = properties.names.map {|name| name.length}.max
48 ["About your application's environment", *properties.map do |property|
49 "%-#{column_width}s %s" % property
50 end] * "\n"
51 end
52
53 alias inspect to_s
54
55 def to_html
56 returning table = '<table>' do
57 properties.each do |(name, value)|
58 table << %(<tr><td class="name">#{CGI.escapeHTML(name.to_s)}</td>)
59 table << %(<td class="value">#{CGI.escapeHTML(value.to_s)}</td></tr>)
60 end
61 table << '</table>'
62 end
63 end
64
65 protected
66 def rails_vendor_root
67 @rails_vendor_root ||= "#{RAILS_ROOT}/vendor/rails"
68 end
69
70 def git_info
71 env_lang, ENV['LC_ALL'] = ENV['LC_ALL'], 'C'
72 Dir.chdir(rails_vendor_root) do
73 silence_stderr { `git log -n 1` }
74 end
75 ensure
76 ENV['LC_ALL'] = env_lang
77 end
78 end
79
80 # The Ruby version and platform, e.g. "1.8.2 (powerpc-darwin8.2.0)".
81 property 'Ruby version', "#{RUBY_VERSION} (#{RUBY_PLATFORM})"
82
83 # The RubyGems version, if it's installed.
84 property 'RubyGems version' do
85 Gem::RubyGemsVersion
86 end
87
88 # The Rails version.
89 property 'Rails version' do
90 Rails::VERSION::STRING
91 end
92
93 # Versions of each Rails component (Active Record, Action Pack,
94 # Active Resource, Action Mailer, and Active Support).
95 components.each do |component|
96 property "#{component.titlecase} version" do
97 component_version(component)
98 end
99 end
100
101 # The Rails Git revision, if it's checked out into vendor/rails.
102 property 'Edge Rails revision' do
103 edge_rails_revision
104 end
105
106 # The application's location on the filesystem.
107 property 'Application root' do
108 File.expand_path(RAILS_ROOT)
109 end
110
111 # The current Rails environment (development, test, or production).
112 property 'Environment' do
113 RAILS_ENV
114 end
115
116 # The name of the database adapter for the current environment.
117 property 'Database adapter' do
118 ActiveRecord::Base.configurations[RAILS_ENV]['adapter']
119 end
120
121 property 'Database schema version' do
122 ActiveRecord::Migrator.current_version rescue nil
123 end
124 end
125 end