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