diff options
Diffstat (limited to 'railties/lib/rails')
23 files changed, 100 insertions, 69 deletions
diff --git a/railties/lib/rails/all.rb b/railties/lib/rails/all.rb index 1a0b4a8d73..82775b7e3b 100644 --- a/railties/lib/rails/all.rb +++ b/railties/lib/rails/all.rb @@ -1,11 +1,8 @@ require "rails" %w( - active_support - active_model active_record action_controller - action_view action_mailer active_resource rails/test_unit @@ -14,4 +11,4 @@ require "rails" require "#{framework}/railtie" rescue LoadError end -end
\ No newline at end of file +end diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb index 40198306f9..14eccd5a6a 100644 --- a/railties/lib/rails/backtrace_cleaner.rb +++ b/railties/lib/rails/backtrace_cleaner.rb @@ -12,7 +12,6 @@ module Rails add_filter { |line| line.sub('./', '/') } # for tests add_gem_filters - add_bundler_filters add_silencer { |line| !APP_DIRS.any? { |dir| line =~ /^#{dir}/ } } end @@ -27,16 +26,6 @@ module Rails } end end - - def add_bundler_filters - return unless defined? Bundler - add_filter { |line| - line.sub(%r{vendor/gems/[^/]+/[^/]+/gems/([^/]+)-([0-9.]+)/(.*)}, '\1 (\2) \3') - } - add_filter { |line| - line.sub(%r{vendor/gems/[^/]+/[^/]+/dirs/([^/]+)/(.*)}, '\1 \2') - } - end end # For installing the BacktraceCleaner in the test/unit diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb index 4240038673..6972e25b29 100644 --- a/railties/lib/rails/commands.rb +++ b/railties/lib/rails/commands.rb @@ -34,8 +34,12 @@ when 'c', 'console' Rails::Console.start(Rails::Application) when 's', 'server' require 'rails/commands/server' - Dir.chdir(ROOT_PATH) - Rails::Server.start + # Initialize the server first, so environment options are set + server = Rails::Server.new + require APP_PATH + + Dir.chdir(Rails::Application.root) + server.start when 'db', 'dbconsole' require 'rails/commands/dbconsole' require APP_PATH @@ -57,11 +61,7 @@ when 'plugin' require 'rails/commands/plugin' when 'runner' require 'rails/commands/runner' - require ENV_PATH - -when '--version', '-v' - puts "Rails #{Rails::VERSION::STRING}" when '--help', '-h' puts HELP_TEXT when '--version', '-v' @@ -70,4 +70,4 @@ when '--version', '-v' else puts "Error: Command not recognized" puts HELP_TEXT -end
\ No newline at end of file +end diff --git a/railties/lib/rails/commands/console.rb b/railties/lib/rails/commands/console.rb index a984eff6e2..50df6ba405 100644 --- a/railties/lib/rails/commands/console.rb +++ b/railties/lib/rails/commands/console.rb @@ -19,7 +19,7 @@ module Rails opt.banner = "Usage: console [environment] [options]" opt.on('-s', '--sandbox', 'Rollback database modifications on exit.') { |v| options[:sandbox] = v } opt.on("--debugger", 'Enable ruby-debugging for the console.') { |v| options[:debugger] = v } - opt.on('--irb') { |v| abort '--irb option is no longer supported. Invoke `/your/choice/of/ruby script/console` instead' } + opt.on('--irb', "DEPRECATED: Invoke `/your/choice/of/ruby script/rails console` instead") { |v| abort '--irb option is no longer supported. Invoke `/your/choice/of/ruby script/rails console` instead' } opt.parse!(ARGV) end diff --git a/railties/lib/rails/commands/destroy.rb b/railties/lib/rails/commands/destroy.rb index 92a06ebdd8..9023c61bf2 100644 --- a/railties/lib/rails/commands/destroy.rb +++ b/railties/lib/rails/commands/destroy.rb @@ -1,7 +1,7 @@ require 'rails/generators' -if ARGV.size == 0 - Rails::Generators.help +if [nil, "-h", "--help"].include?(ARGV.first) + Rails::Generators.help 'destroy' exit end diff --git a/railties/lib/rails/commands/generate.rb b/railties/lib/rails/commands/generate.rb index 5e45d8ab46..7d05a30de8 100755 --- a/railties/lib/rails/commands/generate.rb +++ b/railties/lib/rails/commands/generate.rb @@ -1,7 +1,7 @@ require 'rails/generators' -if ARGV.size == 0 - Rails::Generators.help +if [nil, "-h", "--help"].include?(ARGV.first) + Rails::Generators.help 'generate' exit end diff --git a/railties/lib/rails/commands/performance/benchmarker.rb b/railties/lib/rails/commands/performance/benchmarker.rb index ad84d94dbf..0432261802 100644 --- a/railties/lib/rails/commands/performance/benchmarker.rb +++ b/railties/lib/rails/commands/performance/benchmarker.rb @@ -1,5 +1,5 @@ -if ARGV.empty? - puts "Usage: benchmarker [times] 'Person.expensive_way' 'Person.another_expensive_way' ..." +if [nil, "-h", "--help"].include?(ARGV.first) + puts "Usage: rails benchmarker [times] 'Person.expensive_way' 'Person.another_expensive_way' ..." exit 1 end diff --git a/railties/lib/rails/commands/performance/profiler.rb b/railties/lib/rails/commands/performance/profiler.rb index 50ae411166..6d9717b5cd 100644 --- a/railties/lib/rails/commands/performance/profiler.rb +++ b/railties/lib/rails/commands/performance/profiler.rb @@ -1,5 +1,5 @@ -if ARGV.empty? - $stderr.puts "Usage: profiler 'Person.expensive_method(10)' [times] [flat|graph|graph_html]" +if [nil, "-h", "--help"].include?(ARGV.first) + $stderr.puts "Usage: rails profiler 'Person.expensive_method(10)' [times] [flat|graph|graph_html]" exit(1) end diff --git a/railties/lib/rails/commands/plugin.rb b/railties/lib/rails/commands/plugin.rb index af12df1425..8bcd92a33b 100644 --- a/railties/lib/rails/commands/plugin.rb +++ b/railties/lib/rails/commands/plugin.rb @@ -2,7 +2,7 @@ # # Installing plugins: # -# $ ./script/plugin install continuous_builder asset_timestamping +# $ rails plugin install continuous_builder asset_timestamping # # Specifying revisions: # @@ -319,13 +319,13 @@ module Commands o.separator "" o.separator "EXAMPLES" o.separator " Install a plugin:" - o.separator " #{@script_name} install continuous_builder\n" + o.separator " #{@script_name} plugin install continuous_builder\n" o.separator " Install a plugin from a subversion URL:" - o.separator " #{@script_name} install http://dev.rubyonrails.com/svn/rails/plugins/continuous_builder\n" + o.separator " #{@script_name} plugin install http://dev.rubyonrails.com/svn/rails/plugins/continuous_builder\n" o.separator " Install a plugin from a git URL:" - o.separator " #{@script_name} install git://github.com/SomeGuy/my_awesome_plugin.git\n" + o.separator " #{@script_name} plugin install git://github.com/SomeGuy/my_awesome_plugin.git\n" o.separator " Install a plugin and add a svn:externals entry to vendor/plugins" - o.separator " #{@script_name} install -x continuous_builder\n" + o.separator " #{@script_name} plugin install -x continuous_builder\n" end end @@ -381,7 +381,7 @@ module Commands "Exports the plugin, allowing you to check it into your local repository. Does not enable updates, or add an svn:externals entry.") { |v| @method = :export } o.on( "-q", "--quiet", "Suppresses the output from installation.", - "Ignored if -v is passed (./script/plugin -v install ...)") { |v| @options[:quiet] = true } + "Ignored if -v is passed (rails plugin -v install ...)") { |v| @options[:quiet] = true } o.on( "-r REVISION", "--revision REVISION", "Checks out the given revision from subversion or git.", "Ignored if subversion/git is not used.") { |v| @options[:revision] = v } diff --git a/railties/lib/rails/commands/runner.rb b/railties/lib/rails/commands/runner.rb index 606e04483f..1570b9ab0d 100644 --- a/railties/lib/rails/commands/runner.rb +++ b/railties/lib/rails/commands/runner.rb @@ -35,6 +35,8 @@ ARGV.delete(code_or_file) ENV["RAILS_ENV"] = options[:environment] +require ENV_PATH + begin if code_or_file.nil? $stderr.puts "Run '#{$0} -h' for help." diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index b21ae2a17b..c57660c0d1 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -6,20 +6,21 @@ module Rails class Server < ::Rack::Server class Options def parse!(args) - options = {} - args = args.dup + args, options = args.dup, {} + opt_parser = OptionParser.new do |opts| + opts.banner = "Usage: rails server [options]" opts.on("-p", "--port=port", Integer, - "Runs Rails on the specified port.", "Default: #{options[:Port]}") { |v| options[:Port] = v } + "Runs Rails on the specified port.", "Default: 3000") { |v| options[:Port] = v } opts.on("-b", "--binding=ip", String, - "Binds Rails to the specified ip.", "Default: #{options[:Host]}") { |v| options[:Host] = v } + "Binds Rails to the specified ip.", "Default: 0.0.0.0") { |v| options[:Host] = v } opts.on("-c", "--config=file", String, "Use custom rackup configuration file") { |v| options[:config] = v } opts.on("-d", "--daemon", "Make server run as a Daemon.") { options[:daemonize] = true } opts.on("-u", "--debugger", "Enable ruby-debugging for the server.") { options[:debugger] = true } opts.on("-e", "--environment=name", String, "Specifies the environment to run this server under (test/development/production).", - "Default: #{options[:environment]}") { |v| options[:environment] = v } + "Default: development") { |v| options[:environment] = v } opts.separator "" @@ -33,13 +34,20 @@ module Rails end end + def initialize(*) + super + set_environment + end + def opt_parser Options.new end - def start - ENV["RAILS_ENV"] = options[:environment] + def set_environment + ENV["RAILS_ENV"] ||= options[:environment] + end + def start puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}" puts "=> Rails #{Rails.version} application starting in #{Rails.env} on http://#{options[:Host]}:#{options[:Port]}" puts "=> Call with -d to detach" unless options[:daemonize] @@ -48,7 +56,9 @@ module Rails super ensure - puts 'Exiting' unless options[:daemonize] + # The '-h' option calls exit before @options is set. + # If we call 'options' with it unset, we get double help banners. + puts 'Exiting' unless @options && options[:daemonize] end def middleware diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 80b72252f1..910b26f886 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -91,12 +91,13 @@ module Rails # Generators configuration which uses method missing to wrap it in a nifty DSL. # It also allows you to set generators fallbacks and aliases. class Generators #:nodoc: - attr_accessor :aliases, :options, :fallbacks, :colorize_logging + attr_accessor :aliases, :options, :templates, :fallbacks, :colorize_logging def initialize @aliases = Hash.new { |h,k| h[k] = {} } @options = Hash.new { |h,k| h[k] = {} } @fallbacks = {} + @templates = [] @colorize_logging = true end diff --git a/railties/lib/rails/deprecation.rb b/railties/lib/rails/deprecation.rb index f28da5a6b0..1eb6d804b6 100644 --- a/railties/lib/rails/deprecation.rb +++ b/railties/lib/rails/deprecation.rb @@ -2,6 +2,9 @@ require "active_support/string_inquirer" require "active_support/deprecation" RAILS_ROOT = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do + cattr_accessor :warned + self.warned = false + def target Rails.root end @@ -11,12 +14,17 @@ RAILS_ROOT = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do end def warn(callstack, called, args) - msg = "RAILS_ROOT is deprecated! Use Rails.root instead" - ActiveSupport::Deprecation.warn(msg, callstack) + unless warned + ActiveSupport::Deprecation.warn("RAILS_ROOT is deprecated! Use Rails.root instead", callstack) + self.warned = true + end end end).new RAILS_ENV = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do + cattr_accessor :warned + self.warned = false + def target Rails.env end @@ -26,12 +34,17 @@ RAILS_ENV = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do end def warn(callstack, called, args) - msg = "RAILS_ENV is deprecated! Use Rails.env instead" - ActiveSupport::Deprecation.warn(msg, callstack) + unless warned + ActiveSupport::Deprecation.warn("RAILS_ENV is deprecated! Use Rails.env instead", callstack) + self.warned = true + end end end).new RAILS_DEFAULT_LOGGER = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do + cattr_accessor :warned + self.warned = false + def target Rails.logger end @@ -41,7 +54,9 @@ RAILS_DEFAULT_LOGGER = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) end def warn(callstack, called, args) - msg = "RAILS_DEFAULT_LOGGER is deprecated! Use Rails.logger instead" - ActiveSupport::Deprecation.warn(msg, callstack) + unless warned + ActiveSupport::Deprecation.warn("RAILS_DEFAULT_LOGGER is deprecated! Use Rails.logger instead", callstack) + self.warned = true + end end end).new diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 2b9c4add4f..226d1aaa88 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -99,7 +99,7 @@ module Rails unless abstract_railtie?(base) base.called_from = begin call_stack = caller.map { |p| p.split(':').first } - File.dirname(call_stack.detect { |p| p !~ %r[railties/lib/rails|rack/lib/rack] }) + File.dirname(call_stack.detect { |p| p !~ %r[railties[\w\-]*/lib/rails|rack[\w\-]*/lib/rack] }) end end @@ -185,6 +185,10 @@ module Rails app.metal_loader.paths.unshift(*paths.app.metals.to_a) end + initializer :add_generator_templates do |app| + config.generators.templates.unshift(*paths.lib.templates.to_a) + end + initializer :load_application_initializers do paths.config.initializers.to_a.sort.each do |initializer| load(initializer) diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb index 7d6de91430..93b882f874 100644 --- a/railties/lib/rails/engine/configuration.rb +++ b/railties/lib/rails/engine/configuration.rb @@ -21,6 +21,7 @@ module Rails paths.app.views "app/views" paths.lib "lib", :load_path => true paths.lib.tasks "lib/tasks", :glob => "**/*.rake" + paths.lib.templates "lib/templates" paths.config "config" paths.config.initializers "config/initializers", :glob => "**/*.rb" paths.config.locales "config/locales", :glob => "*.{rb,yml}" diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 5d95f2fa52..c01018aab2 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -66,6 +66,11 @@ module Rails aliases.deep_merge! config.aliases options.deep_merge! config.options fallbacks.merge! config.fallbacks + templates_path.concat config.templates + end + + def self.templates_path + @templates_path ||= [] end def self.aliases #:nodoc: @@ -161,7 +166,7 @@ module Rails end # Show help message with available generators. - def self.help + def self.help(command = 'generate') lookup! namespaces = subclasses.map{ |k| k.namespace } @@ -173,7 +178,7 @@ module Rails groups[base] << namespace end - puts "Usage: rails generate GENERATOR [args] [options]" + puts "Usage: rails #{command} GENERATOR [args] [options]" puts puts "General options:" puts " -h, [--help] # Print generators options and usage" diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index f95b15acce..d41da773c6 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -32,7 +32,7 @@ module Rails options[:git] = "-b #{options[:branch]} #{options[:git]}" if options[:branch] options[:svn] = "-r #{options[:revision]} #{options[:svn]}" if options[:revision] in_root do - run_ruby_script "script/plugin install #{options[:svn] || options[:git]}", :verbose => false + run_ruby_script "script/rails plugin install #{options[:svn] || options[:git]}", :verbose => false end else log "! no git or svn provided for #{name}. Skipping..." @@ -69,7 +69,7 @@ module Rails # otherwise use name (version). parts, message = [ name.inspect ], name if version ||= options.delete(:version) - parts << version + parts << version.inspect message << " (#{version})" end message = options[:git] if options[:git] @@ -81,7 +81,7 @@ module Rails end in_root do - append_file "Gemfile", "gem #{parts.join(", ")}", :verbose => false + append_file "Gemfile", "gem #{parts.join(", ")}\n", :verbose => false end end @@ -226,7 +226,7 @@ module Rails log :generate, what argument = args.map {|arg| arg.to_s }.flatten.join(" ") - in_root { run_ruby_script("script/generate #{what} #{argument}", :verbose => false) } + in_root { run_ruby_script("script/rails generate #{what} #{argument}", :verbose => false) } end # Runs the supplied rake task diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb index dfa0d573c9..9624c35c0b 100644 --- a/railties/lib/rails/generators/base.rb +++ b/railties/lib/rails/generators/base.rb @@ -62,7 +62,7 @@ module Rails # # For example, if the user invoke the controller generator as: # - # ruby script/generate controller Account --test-framework=test_unit + # rails generate controller Account --test-framework=test_unit # # The controller generator will then try to invoke the following generators: # @@ -117,11 +117,11 @@ module Rails # All hooks come with switches for user interface. If the user don't want # to use any test framework, he can do: # - # ruby script/generate controller Account --skip-test-framework + # rails generate controller Account --skip-test-framework # # Or similarly: # - # ruby script/generate controller Account --no-test-framework + # rails generate controller Account --no-test-framework # # ==== Boolean hooks # @@ -133,7 +133,7 @@ module Rails # # Then, if you want, webrat to be invoked, just supply: # - # ruby script/generate controller Account --webrat + # rails generate controller Account --webrat # # The hooks lookup is similar as above: # @@ -213,8 +213,7 @@ module Rails if base.name && base.name !~ /Base$/ Rails::Generators.subclasses << base - if defined?(Rails.root) && Rails.root - path = File.expand_path(File.join(Rails.root, 'lib', 'templates')) + Rails::Generators.templates_path.each do |path| if base.name.include?('::') base.source_paths << File.join(path, base.base_name, base.generator_name) else diff --git a/railties/lib/rails/rack/debugger.rb b/railties/lib/rails/rack/debugger.rb index 0a7b405553..06e23db5f1 100644 --- a/railties/lib/rails/rack/debugger.rb +++ b/railties/lib/rails/rack/debugger.rb @@ -1,10 +1,12 @@ +require 'active_support/core_ext/kernel/requires' + module Rails module Rack class Debugger def initialize(app) @app = app - ARGV.clear # clear ARGV so that script/server options aren't passed to IRB + ARGV.clear # clear ARGV so that rails server options aren't passed to IRB require_library_or_gem 'ruby-debug' ::Debugger.start diff --git a/railties/lib/rails/tasks/documentation.rake b/railties/lib/rails/tasks/documentation.rake index 7095046f21..f7cc6ff4be 100644 --- a/railties/lib/rails/tasks/documentation.rake +++ b/railties/lib/rails/tasks/documentation.rake @@ -14,7 +14,7 @@ namespace :doc do desc 'Generate documentation for the Rails framework. Specify path with PATH="/path/to/rails"' Rake::RDocTask.new("rails") { |rdoc| path = ENV['RAILS_PATH'] || 'vendor/gems/gems' - version = '-3.0.0.beta' unless ENV['RAILS_PATH'] + version = '-3.0.0.beta1' unless ENV['RAILS_PATH'] rdoc.rdoc_dir = 'doc/api' rdoc.template = "#{ENV['template']}.rb" if ENV['template'] rdoc.title = "Rails Framework Documentation" diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb index 350d0b3961..f9aa018cab 100644 --- a/railties/lib/rails/test_help.rb +++ b/railties/lib/rails/test_help.rb @@ -5,6 +5,12 @@ exit("Abort testing: Your Rails environment is not running in test mode!") unles require 'test/unit' require 'active_support/core_ext/kernel/requires' +# TODO: Figure out how to get the Rails::BacktraceFilter into minitest/unit +if defined?(Test::Unit::Util::BacktraceFilter) && ENV['BACKTRACE'].nil? + require 'rails/backtrace_cleaner' + Test::Unit::Util::BacktraceFilter.module_eval { include Rails::BacktraceFilterForTestUnit } +end + if defined?(ActiveRecord) class ActiveSupport::TestCase include ActiveRecord::TestFixtures diff --git a/railties/lib/rails/test_unit/railtie.rb b/railties/lib/rails/test_unit/railtie.rb index 21b9dbc074..d99325a6d8 100644 --- a/railties/lib/rails/test_unit/railtie.rb +++ b/railties/lib/rails/test_unit/railtie.rb @@ -14,4 +14,4 @@ module Rails load "rails/test_unit/testing.rake" end end -end
\ No newline at end of file +end diff --git a/railties/lib/rails/version.rb b/railties/lib/rails/version.rb index c327d4545a..d0c7cb45db 100644 --- a/railties/lib/rails/version.rb +++ b/railties/lib/rails/version.rb @@ -2,7 +2,7 @@ module Rails module VERSION #:nodoc: MAJOR = 3 MINOR = 0 - TINY = "0.beta" + TINY = "0.beta1" STRING = [MAJOR, MINOR, TINY].join('.') end |