diff options
author | Joshua Peek <josh@joshpeek.com> | 2009-01-22 15:13:47 -0600 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-01-22 15:13:47 -0600 |
commit | cc0b5fa9930dcc60914e21b518b3c54109243cfa (patch) | |
tree | 3b5c65d8d0329388730542093314028630b0945a /railties/lib | |
parent | e57cb2629ac4971a5dcb1cf8bb2f6d0509317928 (diff) | |
parent | ccda96093a3bf3fb360f7c6d61bbbf341b2ae034 (diff) | |
download | rails-cc0b5fa9930dcc60914e21b518b3c54109243cfa.tar.gz rails-cc0b5fa9930dcc60914e21b518b3c54109243cfa.tar.bz2 rails-cc0b5fa9930dcc60914e21b518b3c54109243cfa.zip |
Merge branch 'master' into 3-0-unstable
Conflicts:
ci/cruise_config.rb
Diffstat (limited to 'railties/lib')
-rwxr-xr-x | railties/lib/commands/performance/request.rb | 6 | ||||
-rw-r--r-- | railties/lib/dispatcher.rb | 2 | ||||
-rw-r--r-- | railties/lib/initializer.rb | 17 | ||||
-rw-r--r-- | railties/lib/rails/backtrace_cleaner.rb | 5 | ||||
-rw-r--r-- | railties/lib/rails_generator/commands.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails_generator/generators/applications/app/app_generator.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails_generator/generators/applications/app/template_runner.rb | 139 | ||||
-rw-r--r-- | railties/lib/test_help.rb | 1 |
8 files changed, 90 insertions, 84 deletions
diff --git a/railties/lib/commands/performance/request.rb b/railties/lib/commands/performance/request.rb deleted file mode 100755 index 1773886487..0000000000 --- a/railties/lib/commands/performance/request.rb +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env ruby -require 'config/environment' -require 'application' -require 'action_controller/request_profiler' - -ActionController::RequestProfiler.run(ARGV) diff --git a/railties/lib/dispatcher.rb b/railties/lib/dispatcher.rb index 0bad45d9d8..9f8b59aa3d 100644 --- a/railties/lib/dispatcher.rb +++ b/railties/lib/dispatcher.rb @@ -1,5 +1,5 @@ #-- -# Copyright (c) 2004-2008 David Heinemeier Hansson +# Copyright (c) 2004-2009 David Heinemeier Hansson # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 637fe74313..be04873855 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -370,8 +370,9 @@ Run `rake gems:install` to install the missing gems. def load_view_paths if configuration.frameworks.include?(:action_view) if configuration.cache_classes - ActionController::Base.view_paths.load if configuration.frameworks.include?(:action_controller) - ActionMailer::Base.template_root.load if configuration.frameworks.include?(:action_mailer) + view_path = ActionView::Template::EagerPath.new(configuration.view_path) + ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller) + ActionMailer::Base.template_root = view_path if configuration.frameworks.include?(:action_mailer) end end end @@ -407,12 +408,18 @@ Run `rake gems:install` to install the missing gems. if configuration.frameworks.include?(:active_record) ActiveRecord::Base.configurations = configuration.database_configuration ActiveRecord::Base.establish_connection + configuration.middleware.use ActiveRecord::QueryCache end end def initialize_cache unless defined?(RAILS_CACHE) silence_warnings { Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store(configuration.cache_store) } + + if RAILS_CACHE.respond_to?(:middleware) + # Insert middleware to setup and teardown local cache for each request + configuration.middleware.insert_after(:"ActionController::Failsafe", RAILS_CACHE.middleware) + end end end @@ -473,7 +480,7 @@ Run `rake gems:install` to install the missing gems. # set to use Configuration#view_path. def initialize_framework_views if configuration.frameworks.include?(:action_view) - view_path = ActionView::PathSet::Path.new(configuration.view_path, false) + view_path = ActionView::Template::Path.new(configuration.view_path) ActionMailer::Base.template_root ||= view_path if configuration.frameworks.include?(:action_mailer) ActionController::Base.view_paths = view_path if configuration.frameworks.include?(:action_controller) && ActionController::Base.view_paths.empty? end @@ -536,7 +543,9 @@ Run `rake gems:install` to install the missing gems. end def initialize_metal - configuration.middleware.use Rails::Rack::Metal + configuration.middleware.insert_before( + :"ActionController::RewindableInput", + Rails::Rack::Metal, :if => Rails::Rack::Metal.metals.any?) end # Initializes framework-specific settings for each of the loaded frameworks diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb index 94d34cda39..e1b422716d 100644 --- a/railties/lib/rails/backtrace_cleaner.rb +++ b/railties/lib/rails/backtrace_cleaner.rb @@ -2,7 +2,7 @@ module Rails class BacktraceCleaner < ActiveSupport::BacktraceCleaner ERB_METHOD_SIG = /:in `_run_erb_.*/ - VENDOR_DIRS = %w( vendor/plugins vendor/gems vendor/rails ) + VENDOR_DIRS = %w( vendor/gems vendor/rails ) SERVER_DIRS = %w( lib/mongrel bin/mongrel lib/passenger bin/passenger-spawn-server lib/rack ) @@ -15,11 +15,12 @@ module Rails def initialize super - add_filter { |line| line.sub(RAILS_ROOT, '') } + add_filter { |line| line.sub("#{RAILS_ROOT}/", '') } add_filter { |line| line.sub(ERB_METHOD_SIG, '') } add_filter { |line| line.sub('./', '/') } # for tests add_filter { |line| line.sub(/(#{GEMS_DIR})\/gems\/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) \4')} # http://gist.github.com/30430 add_silencer { |line| ALL_NOISE.any? { |dir| line.include?(dir) } } + add_silencer { |line| line =~ %r(vendor/plugins/[^\/]+/lib) } end end diff --git a/railties/lib/rails_generator/commands.rb b/railties/lib/rails_generator/commands.rb index cacb3807d6..299044c3d7 100644 --- a/railties/lib/rails_generator/commands.rb +++ b/railties/lib/rails_generator/commands.rb @@ -294,7 +294,7 @@ HELP file(relative_source, relative_destination, template_options) do |file| # Evaluate any assignments in a temporary, throwaway binding. vars = template_options[:assigns] || {} - b = binding + b = template_options[:binding] || binding vars.each { |k,v| eval "#{k} = vars[:#{k}] || vars['#{k}']", b } # Render the source file with the temporary binding. 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 795a0d7653..2c31d89538 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -151,7 +151,7 @@ class AppGenerator < Rails::Generator::Base def create_script_files(m) %w( about console dbconsole destroy generate runner server plugin - performance/benchmarker performance/profiler performance/request + performance/benchmarker performance/profiler ).each do |file| m.file "bin/#{file}", "script/#{file}", { :chmod => 0755, diff --git a/railties/lib/rails_generator/generators/applications/app/template_runner.rb b/railties/lib/rails_generator/generators/applications/app/template_runner.rb index c6113648e6..84e36ecc1b 100644 --- a/railties/lib/rails_generator/generators/applications/app/template_runner.rb +++ b/railties/lib/rails_generator/generators/applications/app/template_runner.rb @@ -8,23 +8,24 @@ require 'fileutils' module Rails class TemplateRunner attr_reader :root + attr_writer :logger def initialize(template, root = '') # :nodoc: - @root = File.join(Dir.pwd, root) + @root = File.expand_path(File.directory?(root) ? root : File.join(Dir.pwd, root)) - puts "applying template: #{template}" + log 'applying', "template: #{template}" load_template(template) - puts "#{template} applied." + log 'applied', "#{template}" end def load_template(template) begin code = open(template).read in_root { self.instance_eval(code) } - rescue LoadError - raise "The template [#{template}] could not be loaded." + rescue LoadError, Errno::ENOENT => e + raise "The template [#{template}] could not be loaded. Error: #{e}" end end @@ -41,8 +42,8 @@ module Rails # # file("config/apach.conf", "your apache config") # - def file(filename, data = nil, &block) - puts "creating file #{filename}" + def file(filename, data = nil, log_action = true, &block) + log 'file', filename if log_action dir, file = [File.dirname(filename), File.basename(filename)] inside(dir) do @@ -66,7 +67,7 @@ module Rails # plugin 'restful-authentication', :svn => 'svn://svnhub.com/technoweenie/restful-authentication/trunk' # def plugin(name, options) - puts "installing plugin #{name}" + log 'plugin', name if options[:git] && options[:submodule] in_root do @@ -74,28 +75,36 @@ module Rails end elsif options[:git] || options[:svn] in_root do - `script/plugin install #{options[:svn] || options[:git]}` + run("script/plugin install #{options[:svn] || options[:git]}", false) end else - puts "! no git or svn provided for #{name}. skipping..." + log "! no git or svn provided for #{name}. skipping..." end end # Adds an entry into config/environment.rb for the supplied gem : def gem(name, options = {}) - puts "adding gem #{name}" + log 'gem', name - sentinel = 'Rails::Initializer.run do |config|' gems_code = "config.gem '#{name}'" if options.any? - opts = options.inject([]) {|result, h| result << [":#{h[0]} => '#{h[1]}'"] }.join(", ") + opts = options.inject([]) {|result, h| result << [":#{h[0]} => '#{h[1]}'"] }.sort.join(", ") gems_code << ", #{opts}" end + environment gems_code + end + + # Adds a line inside the Initializer block for config/environment.rb. Used by #gem + def environment(data = nil, &block) + sentinel = 'Rails::Initializer.run do |config|' + + data = block.call if !data && block_given? + in_root do gsub_file 'config/environment.rb', /(#{Regexp.escape(sentinel)})/mi do |match| - "#{match}\n #{gems_code}" + "#{match}\n " << data end end end @@ -111,11 +120,11 @@ module Rails def git(command = {}) in_root do if command.is_a?(Symbol) - puts "running git #{command}" + log 'running', "git #{command}" Git.run(command.to_s) else command.each do |command, options| - puts "running git #{command} #{options}" + log 'running', "git #{command} #{options}" Git.run("#{command} #{options}") end end @@ -135,16 +144,8 @@ module Rails # vendor("foreign.rb", "# Foreign code is fun") # def vendor(filename, data = nil, &block) - puts "vendoring file #{filename}" - inside("vendor") do |folder| - File.open("#{folder}/#{filename}", "w") do |f| - if block_given? - f.write(block.call) - else - f.write(data) - end - end - end + log 'vendoring', filename + file("vendor/#{filename}", data, false, &block) end # Create a new file in the lib/ directory. Code can be specified @@ -158,17 +159,9 @@ module Rails # # lib("foreign.rb", "# Foreign code is fun") # - def lib(filename, data = nil) - puts "add lib file #{filename}" - inside("lib") do |folder| - File.open("#{folder}/#{filename}", "w") do |f| - if block_given? - f.write(block.call) - else - f.write(data) - end - end - end + def lib(filename, data = nil, &block) + log 'lib', filename + file("lib/#{filename}", data, false, &block) end # Create a new Rakefile with the provided code (either in a block or a string). @@ -190,16 +183,8 @@ module Rails # rakefile("seed.rake", "puts 'im plantin ur seedz'") # def rakefile(filename, data = nil, &block) - puts "adding rakefile #{filename}" - inside("lib/tasks") do |folder| - File.open("#{folder}/#{filename}", "w") do |f| - if block_given? - f.write(block.call) - else - f.write(data) - end - end - end + log 'rakefile', filename + file("lib/tasks/#{filename}", data, false, &block) end # Create a new initializer with the provided code (either in a block or a string). @@ -219,16 +204,8 @@ module Rails # initializer("api.rb", "API_KEY = '123456'") # def initializer(filename, data = nil, &block) - puts "adding initializer #{filename}" - inside("config/initializers") do |folder| - File.open("#{folder}/#{filename}", "w") do |f| - if block_given? - f.write(block.call) - else - f.write(data) - end - end - end + log 'initializer', filename + file("config/initializers/#{filename}", data, false, &block) end # Generate something using a generator from Rails or a plugin. @@ -240,10 +217,10 @@ module Rails # generate(:authenticated, "user session") # def generate(what, *args) - puts "generating #{what}" + log 'generating', what argument = args.map(&:to_s).flatten.join(" ") - in_root { `#{root}/script/generate #{what} #{argument}` } + in_root { run("script/generate #{what} #{argument}", false) } end # Executes a command @@ -254,8 +231,8 @@ module Rails # run('ln -s ~/edge rails) # end # - def run(command) - puts "executing #{command} from #{Dir.pwd}" + def run(command, log_action = true) + log 'executing', "#{command} from #{Dir.pwd}" if log_action `#{command}` end @@ -268,10 +245,10 @@ module Rails # rake("gems:install", :sudo => true) # def rake(command, options = {}) - puts "running rake task #{command}" + log 'rake', command env = options[:env] || 'development' sudo = options[:sudo] ? 'sudo ' : '' - in_root { `#{sudo}rake #{command} RAILS_ENV=#{env}` } + in_root { run("#{sudo}rake #{command} RAILS_ENV=#{env}", false) } end # Just run the capify command in root @@ -281,7 +258,8 @@ module Rails # capify! # def capify! - in_root { `capify .` } + log 'capifying' + in_root { run('capify .', false) } end # Add Rails to /vendor/rails @@ -291,8 +269,8 @@ module Rails # freeze! # def freeze!(args = {}) - puts "vendoring rails edge" - in_root { `rake rails:freeze:edge` } + log 'vendor', 'rails edge' + in_root { run('rake rails:freeze:edge', false) } end # Make an entry in Rails routing file conifg/routes.rb @@ -302,6 +280,7 @@ module Rails # route "map.root :controller => :welcome" # def route(routing_code) + log 'route', routing_code sentinel = 'ActionController::Routing::Routes.draw do |map|' in_root do @@ -321,7 +300,7 @@ module Rails # freeze! if ask("Should I freeze the latest Rails?") == "yes" # def ask(string) - puts string + log '', string gets.strip end @@ -359,6 +338,12 @@ module Rails !yes?(question) end + # Run a regular expression replacement on a file + # + # ==== Example + # + # gsub_file 'app/controllers/application_controller.rb', /#\s*(filter_parameter_logging :password)/, '\1' + # def gsub_file(relative_destination, regexp, *args, &block) path = destination_path(relative_destination) content = File.read(path).gsub(regexp, *args, &block) @@ -368,5 +353,23 @@ module Rails def destination_path(relative_destination) File.join(root, relative_destination) end + + def log(action, message = '') + logger.log(action, message) + end + + def logger + @logger ||= Rails::Generator::Base.logger + end + + def logger + @logger ||= if defined?(Rails::Generator::Base) + Rails::Generator::Base.logger + else + require 'rails_generator/simple_logger' + Rails::Generator::SimpleLogger.new(STDOUT) + end + end + end -end
\ No newline at end of file +end diff --git a/railties/lib/test_help.rb b/railties/lib/test_help.rb index b5c92c1790..ee24ea3a45 100644 --- a/railties/lib/test_help.rb +++ b/railties/lib/test_help.rb @@ -3,7 +3,6 @@ silence_warnings { RAILS_ENV = "test" } require 'test/unit' -require 'active_support/test_case' require 'action_controller/test_case' require 'action_view/test_case' require 'action_controller/integration' |