Updated README.rdoc again
[feedcatcher.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 frameworks
24 %w( active_record action_pack active_resource action_mailer active_support )
25 end
26
27 def framework_version(framework)
28 require "#{framework}/version"
29 "#{framework.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 property 'Rack version' do
89 ::Rack.release
90 end
91
92 # The Rails version.
93 property 'Rails version' do
94 Rails::VERSION::STRING
95 end
96
97 # Versions of each Rails framework (Active Record, Action Pack,
98 # Active Resource, Action Mailer, and Active Support).
99 frameworks.each do |framework|
100 property "#{framework.titlecase} version" do
101 framework_version(framework)
102 end
103 end
104
105 # The Rails Git revision, if it's checked out into vendor/rails.
106 property 'Edge Rails revision' do
107 edge_rails_revision
108 end
109
110 # The application's location on the filesystem.
111 property 'Application root' do
112 File.expand_path(RAILS_ROOT)
113 end
114
115 # The current Rails environment (development, test, or production).
116 property 'Environment' do
117 RAILS_ENV
118 end
119
120 # The name of the database adapter for the current environment.
121 property 'Database adapter' do
122 ActiveRecord::Base.configurations[RAILS_ENV]['adapter']
123 end
124
125 property 'Database schema version' do
126 ActiveRecord::Migrator.current_version rescue nil
127 end
128 end
129 end