diff options
author | Sam Stephenson <sam@37signals.com> | 2005-11-05 14:30:47 +0000 |
---|---|---|
committer | Sam Stephenson <sam@37signals.com> | 2005-11-05 14:30:47 +0000 |
commit | 71b032a0a6a4f68354db7cb41e77443aa091580b (patch) | |
tree | acd7a0246f7919fa791d74224432ee98cf7968ad | |
parent | 1f6b09f67c7d15e4db5960a09ad3b724a1e01d7f (diff) | |
download | rails-71b032a0a6a4f68354db7cb41e77443aa091580b.tar.gz rails-71b032a0a6a4f68354db7cb41e77443aa091580b.tar.bz2 rails-71b032a0a6a4f68354db7cb41e77443aa091580b.zip |
Added script/about to display formatted Rails::Info output
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2883 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | railties/CHANGELOG | 2 | ||||
-rw-r--r-- | railties/Rakefile | 2 | ||||
-rw-r--r-- | railties/bin/about | 3 | ||||
-rw-r--r-- | railties/lib/commands/about.rb | 2 | ||||
-rw-r--r-- | railties/lib/info.rb | 24 | ||||
-rw-r--r-- | railties/lib/rails_generator/generators/applications/app/app_generator.rb | 2 | ||||
-rw-r--r-- | railties/test/info_test.rb | 14 |
7 files changed, 36 insertions, 13 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 8e48b6e0a9..e520f04fc1 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added script/about to display formatted Rails::Info output [Sam Stephenson] + * Added Rails::Info to catalog assorted information about a Rails application's environment [Sam Stephenson] * Tail the logfile when running script/lighttpd in the foreground [Sam Stephenson] diff --git a/railties/Rakefile b/railties/Rakefile index 01395e72ea..b1b4a8de55 100644 --- a/railties/Rakefile +++ b/railties/Rakefile @@ -37,7 +37,7 @@ LOG_FILES = %w( server.log development.log test.log production.log ) HTML_FILES = %w( 404.html 500.html index.html robots.txt favicon.ico javascripts/prototype.js javascripts/effects.js javascripts/dragdrop.js javascripts/controls.js ) -BIN_FILES = %w( breakpointer console destroy generate performance/benchmarker performance/profiler process/reaper process/spawner process/spinner runner server lighttpd plugin ) +BIN_FILES = %w( about breakpointer console destroy generate performance/benchmarker performance/profiler process/reaper process/spawner process/spinner runner server lighttpd plugin ) VENDOR_LIBS = %w( actionpack activerecord actionmailer activesupport actionwebservice railties ) diff --git a/railties/bin/about b/railties/bin/about new file mode 100644 index 0000000000..6213338119 --- /dev/null +++ b/railties/bin/about @@ -0,0 +1,3 @@ +#!/usr/local/bin/ruby +require File.dirname(__FILE__) + '/../config/boot' +require 'commands/about'
\ No newline at end of file diff --git a/railties/lib/commands/about.rb b/railties/lib/commands/about.rb new file mode 100644 index 0000000000..313bc18c6a --- /dev/null +++ b/railties/lib/commands/about.rb @@ -0,0 +1,2 @@ +require 'environment' +puts Rails::Info diff --git a/railties/lib/info.rb b/railties/lib/info.rb index 74cb41e8bc..2104f4d6e6 100644 --- a/railties/lib/info.rb +++ b/railties/lib/info.rb @@ -1,7 +1,15 @@ module Rails module Info mattr_accessor :properties - @@properties = [] + class << (@@properties = []) + def names + map {|(name, )| name} + end + + def value_for(property_name) + find {|(name, )| name == property_name}.last rescue nil + end + end class << self #:nodoc: def property(name, value = nil) @@ -19,10 +27,19 @@ module Rails require "#{component}/version" "#{component.classify}::Version::STRING".constantize end - + def edge_rails_revision svn_info[/^Revision: (\d+)/, 1] || 'unknown' end + + def to_s + column_width = properties.names.map {|name| name.length}.max + ["About your application's environment", *properties.map do |property| + "%-#{column_width}s %s" % property + end] * "\n" + end + + alias inspect to_s protected def svn_info @@ -53,6 +70,9 @@ module Rails edge_rails_revision end + # The application's location on the filesystem. + property 'Application root', File.expand_path(RAILS_ROOT) + # The current Rails environment (development, test, or production). property 'Environment' do RAILS_ENV diff --git a/railties/lib/rails_generator/generators/applications/app/app_generator.rb b/railties/lib/rails_generator/generators/applications/app/app_generator.rb index 14c3043fac..1babf46343 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -49,7 +49,7 @@ class AppGenerator < Rails::Generator::Base m.file "environments/test.rb", "config/environments/test.rb" # Scripts - %w( breakpointer console destroy generate performance/benchmarker performance/profiler process/reaper process/spawner process/spinner runner server lighttpd plugin ).each do |file| + %w( about breakpointer console destroy generate performance/benchmarker performance/profiler process/reaper process/spawner process/spinner runner server lighttpd plugin ).each do |file| m.file "bin/#{file}", "script/#{file}", script_options end diff --git a/railties/test/info_test.rb b/railties/test/info_test.rb index 2c6e28779d..8faef428a8 100644 --- a/railties/test/info_test.rb +++ b/railties/test/info_test.rb @@ -57,21 +57,17 @@ class InfoTest < Test::Unit::TestCase end protected - def property_names - Rails::Info.properties.map {|(name, )| name} + def properties + Rails::Info.properties end - - def property_value(property_name) - Rails::Info.properties.find {|(name, )| property_name == name}.last - end - + def property_defined?(property_name) - property_names.include? property_name + properties.names.include? property_name end def assert_property(property_name, value) raise "Property #{property_name.inspect} not defined" unless property_defined? property_name - assert_equal value, property_value(property_name) + assert_equal value, properties.value_for(property_name) end end
\ No newline at end of file |