2009-05-16 15:28:25 -04:00
|
|
|
require "active_support/core_ext/object/misc"
|
|
|
|
require "cgi"
|
|
|
|
require "active_support/core_ext/cgi"
|
|
|
|
|
2005-11-04 23:44:33 -05:00
|
|
|
module Rails
|
|
|
|
module Info
|
|
|
|
mattr_accessor :properties
|
2005-11-05 09:30:47 -05:00
|
|
|
class << (@@properties = [])
|
|
|
|
def names
|
2009-05-16 15:28:25 -04:00
|
|
|
map {|val| val.first }
|
2005-11-05 09:30:47 -05:00
|
|
|
end
|
2007-12-18 20:18:45 -05:00
|
|
|
|
2005-11-05 09:30:47 -05:00
|
|
|
def value_for(property_name)
|
2007-12-18 23:21:02 -05:00
|
|
|
if property = assoc(property_name)
|
2007-12-18 20:18:45 -05:00
|
|
|
property.last
|
|
|
|
end
|
2005-11-05 09:30:47 -05:00
|
|
|
end
|
|
|
|
end
|
2007-12-18 20:18:45 -05:00
|
|
|
|
2005-11-04 23:44:33 -05:00
|
|
|
class << self #:nodoc:
|
|
|
|
def property(name, value = nil)
|
|
|
|
value ||= yield
|
2007-12-18 23:21:02 -05:00
|
|
|
properties << [name, value] if value
|
2005-11-04 23:44:33 -05:00
|
|
|
rescue Exception
|
|
|
|
end
|
|
|
|
|
2008-11-24 21:47:42 -05:00
|
|
|
def frameworks
|
2007-09-22 13:21:40 -04:00
|
|
|
%w( active_record action_pack active_resource action_mailer active_support )
|
2005-11-04 23:44:33 -05:00
|
|
|
end
|
2007-12-18 23:21:02 -05:00
|
|
|
|
2008-11-24 21:47:42 -05:00
|
|
|
def framework_version(framework)
|
2009-08-31 18:58:54 -04:00
|
|
|
if Object.const_defined?(framework.classify)
|
|
|
|
require "#{framework}/version"
|
|
|
|
"#{framework.classify}::VERSION::STRING".constantize
|
|
|
|
end
|
2005-11-04 23:44:33 -05:00
|
|
|
end
|
2007-12-18 23:21:02 -05:00
|
|
|
|
2008-04-22 16:44:13 -04:00
|
|
|
def edge_rails_revision(info = git_info)
|
|
|
|
info[/commit ([a-z0-9-]+)/, 1] || freeze_edge_version
|
2005-11-04 23:44:33 -05:00
|
|
|
end
|
2006-03-05 16:38:51 -05:00
|
|
|
|
|
|
|
def freeze_edge_version
|
2007-12-10 00:54:46 -05:00
|
|
|
if File.exist?(rails_vendor_root)
|
2006-04-02 22:38:12 -04:00
|
|
|
begin
|
|
|
|
Dir[File.join(rails_vendor_root, 'REVISION_*')].first.scan(/_(\d+)$/).first.first
|
|
|
|
rescue
|
2006-04-02 22:46:22 -04:00
|
|
|
Dir[File.join(rails_vendor_root, 'TAG_*')].first.scan(/_(.+)$/).first.first rescue 'unknown'
|
2006-04-02 22:38:12 -04:00
|
|
|
end
|
2006-03-05 16:38:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-11-05 09:30:47 -05:00
|
|
|
def to_s
|
|
|
|
column_width = properties.names.map {|name| name.length}.max
|
2010-02-03 12:07:22 -05:00
|
|
|
info = properties.map do |name, value|
|
|
|
|
value = value.join(", ") if value.is_a?(Array)
|
|
|
|
"%-#{column_width}s %s" % [name, value]
|
|
|
|
end
|
|
|
|
info.unshift "About your application's environment"
|
|
|
|
info * "\n"
|
2005-11-05 09:30:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
alias inspect to_s
|
2007-12-18 23:21:02 -05:00
|
|
|
|
2005-11-07 23:26:34 -05:00
|
|
|
def to_html
|
2009-05-16 15:28:25 -04:00
|
|
|
(table = '<table>').tap do
|
2005-11-07 23:26:34 -05:00
|
|
|
properties.each do |(name, value)|
|
2006-03-29 10:11:47 -05:00
|
|
|
table << %(<tr><td class="name">#{CGI.escapeHTML(name.to_s)}</td>)
|
2009-04-02 12:54:52 -04:00
|
|
|
formatted_value = if value.kind_of?(Array)
|
|
|
|
"<ul>" + value.map { |v| "<li>#{CGI.escapeHTML(v.to_s)}</li>" }.join + "</ul>"
|
|
|
|
else
|
|
|
|
CGI.escapeHTML(value.to_s)
|
|
|
|
end
|
|
|
|
table << %(<td class="value">#{formatted_value}</td></tr>)
|
2005-11-07 23:26:34 -05:00
|
|
|
end
|
|
|
|
table << '</table>'
|
|
|
|
end
|
|
|
|
end
|
2006-03-01 11:30:09 -05:00
|
|
|
|
|
|
|
protected
|
2006-03-05 16:38:51 -05:00
|
|
|
def rails_vendor_root
|
2009-10-16 15:49:39 -04:00
|
|
|
@rails_vendor_root ||= "#{Rails.root}/vendor/rails"
|
2006-03-05 16:38:51 -05:00
|
|
|
end
|
|
|
|
|
2008-04-22 16:44:13 -04:00
|
|
|
def git_info
|
2006-03-01 11:30:09 -05:00
|
|
|
env_lang, ENV['LC_ALL'] = ENV['LC_ALL'], 'C'
|
2006-03-05 16:38:51 -05:00
|
|
|
Dir.chdir(rails_vendor_root) do
|
2008-04-22 16:44:13 -04:00
|
|
|
silence_stderr { `git log -n 1` }
|
2006-03-01 11:30:09 -05:00
|
|
|
end
|
|
|
|
ensure
|
|
|
|
ENV['LC_ALL'] = env_lang
|
2005-11-04 23:44:33 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# The Ruby version and platform, e.g. "1.8.2 (powerpc-darwin8.2.0)".
|
|
|
|
property 'Ruby version', "#{RUBY_VERSION} (#{RUBY_PLATFORM})"
|
|
|
|
|
|
|
|
# The RubyGems version, if it's installed.
|
|
|
|
property 'RubyGems version' do
|
|
|
|
Gem::RubyGemsVersion
|
|
|
|
end
|
2007-12-18 23:21:02 -05:00
|
|
|
|
2009-03-14 11:37:20 -04:00
|
|
|
property 'Rack version' do
|
|
|
|
::Rack.release
|
|
|
|
end
|
|
|
|
|
2005-11-05 13:04:52 -05:00
|
|
|
# The Rails version.
|
|
|
|
property 'Rails version' do
|
2005-11-16 19:32:16 -05:00
|
|
|
Rails::VERSION::STRING
|
2005-11-05 13:04:52 -05:00
|
|
|
end
|
2007-12-18 23:21:02 -05:00
|
|
|
|
2008-11-24 21:47:42 -05:00
|
|
|
# Versions of each Rails framework (Active Record, Action Pack,
|
2007-10-15 04:45:23 -04:00
|
|
|
# Active Resource, Action Mailer, and Active Support).
|
2008-11-24 21:47:42 -05:00
|
|
|
frameworks.each do |framework|
|
|
|
|
property "#{framework.titlecase} version" do
|
|
|
|
framework_version(framework)
|
2005-11-04 23:44:33 -05:00
|
|
|
end
|
|
|
|
end
|
2007-12-18 23:21:02 -05:00
|
|
|
|
2009-04-02 12:54:52 -04:00
|
|
|
property 'Middleware' do
|
2010-01-19 23:25:10 -05:00
|
|
|
Rails.configuration.middleware.active.map(&:inspect)
|
2009-04-02 12:54:52 -04:00
|
|
|
end
|
|
|
|
|
2008-04-22 16:44:13 -04:00
|
|
|
# The Rails Git revision, if it's checked out into vendor/rails.
|
2005-11-04 23:44:33 -05:00
|
|
|
property 'Edge Rails revision' do
|
|
|
|
edge_rails_revision
|
|
|
|
end
|
2007-12-18 23:21:02 -05:00
|
|
|
|
2005-11-05 09:30:47 -05:00
|
|
|
# The application's location on the filesystem.
|
2005-11-05 13:04:52 -05:00
|
|
|
property 'Application root' do
|
2009-10-16 15:49:39 -04:00
|
|
|
File.expand_path(Rails.root)
|
2005-11-05 13:04:52 -05:00
|
|
|
end
|
|
|
|
|
2005-11-04 23:44:33 -05:00
|
|
|
# The current Rails environment (development, test, or production).
|
|
|
|
property 'Environment' do
|
2010-01-12 08:11:47 -05:00
|
|
|
Rails.env
|
2005-11-04 23:44:33 -05:00
|
|
|
end
|
2007-12-18 23:21:02 -05:00
|
|
|
|
2005-11-04 23:44:33 -05:00
|
|
|
# The name of the database adapter for the current environment.
|
|
|
|
property 'Database adapter' do
|
2010-01-12 08:11:47 -05:00
|
|
|
ActiveRecord::Base.configurations[Rails.env]['adapter']
|
2005-11-04 23:44:33 -05:00
|
|
|
end
|
2006-03-05 16:38:51 -05:00
|
|
|
|
|
|
|
property 'Database schema version' do
|
|
|
|
ActiveRecord::Migrator.current_version rescue nil
|
|
|
|
end
|
2005-11-04 23:44:33 -05:00
|
|
|
end
|
|
|
|
end
|