aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/rails')
-rw-r--r--railties/lib/rails/application.rb195
-rw-r--r--railties/lib/rails/backtrace_cleaner.rb10
-rw-r--r--railties/lib/rails/commands/about.rb1
-rw-r--r--railties/lib/rails/commands/console.rb2
-rw-r--r--railties/lib/rails/commands/dbconsole.rb2
-rw-r--r--railties/lib/rails/commands/destroy.rb4
-rwxr-xr-xrailties/lib/rails/commands/generate.rb4
-rw-r--r--railties/lib/rails/commands/performance/benchmarker.rb3
-rw-r--r--railties/lib/rails/commands/performance/profiler.rb4
-rw-r--r--railties/lib/rails/commands/runner.rb2
-rw-r--r--railties/lib/rails/commands/server.rb8
-rw-r--r--railties/lib/rails/commands/update.rb1
-rw-r--r--railties/lib/rails/configuration.rb290
-rw-r--r--railties/lib/rails/core.rb40
-rw-r--r--railties/lib/rails/deprecation.rb25
-rw-r--r--railties/lib/rails/gem_builder.rb21
-rw-r--r--railties/lib/rails/gem_dependency.rb311
-rw-r--r--railties/lib/rails/generators.rb68
-rw-r--r--railties/lib/rails/generators/actions.rb63
-rw-r--r--railties/lib/rails/generators/active_model.rb18
-rw-r--r--railties/lib/rails/generators/active_record.rb35
-rw-r--r--railties/lib/rails/generators/base.rb80
-rw-r--r--railties/lib/rails/generators/named_base.rb5
-rw-r--r--railties/lib/rails/generators/rails/app/app_generator.rb17
-rw-r--r--railties/lib/rails/generators/rails/app/templates/Gemfile18
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/Rakefile2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config.ru4
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/application.rb41
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/boot.rb156
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environment.rb56
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/about (renamed from railties/lib/rails/generators/rails/app/templates/script/about.tt)3
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/console2
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/console.tt3
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/dbconsole2
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/dbconsole.tt3
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/destroy2
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/destroy.tt3
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/generate2
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/generate.tt3
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/performance/benchmarker2
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/performance/benchmarker.tt3
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/performance/profiler2
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/performance/profiler.tt3
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/plugin2
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/plugin.tt3
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/runner2
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/runner.tt3
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/server2
-rwxr-xr-xrailties/lib/rails/generators/rails/app/templates/script/server.tt3
-rw-r--r--railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb2
-rw-r--r--railties/lib/rails/generators/resource_helpers.rb25
-rw-r--r--railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb2
-rw-r--r--railties/lib/rails/initializable.rb134
-rw-r--r--railties/lib/rails/initializer.rb15
-rw-r--r--railties/lib/rails/paths.rb18
-rw-r--r--railties/lib/rails/plugin.rb202
-rw-r--r--railties/lib/rails/plugin/loader.rb200
-rw-r--r--railties/lib/rails/plugin/locator.rb100
-rw-r--r--railties/lib/rails/ruby_version_check.rb11
-rw-r--r--railties/lib/rails/tasks.rb5
-rw-r--r--railties/lib/rails/tasks/databases.rake24
-rw-r--r--railties/lib/rails/tasks/framework.rake13
-rw-r--r--railties/lib/rails/tasks/gems.rake78
-rw-r--r--railties/lib/rails/tasks/misc.rake2
-rw-r--r--railties/lib/rails/tasks/routes.rake9
-rw-r--r--railties/lib/rails/tasks/statistics.rake5
-rw-r--r--railties/lib/rails/test_help.rb2
-rwxr-xr-xrailties/lib/rails/vendor/thor-0.11.6/bin/rake2thor87
-rwxr-xr-xrailties/lib/rails/vendor/thor-0.11.6/bin/thor7
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/CHANGELOG.rdoc (renamed from railties/lib/rails/vendor/thor-0.11.6/CHANGELOG.rdoc)7
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/LICENSE (renamed from railties/lib/rails/vendor/thor-0.11.6/LICENSE)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/README.rdoc (renamed from railties/lib/rails/vendor/thor-0.11.6/README.rdoc)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/Thorfile63
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor.rb)1
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/create_file.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/create_file.rb)1
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/directory.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/directory.rb)18
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/empty_directory.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/empty_directory.rb)1
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/file_manipulation.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/file_manipulation.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/inject_into_file.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/inject_into_file.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/base.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/base.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/core_ext/hash_with_indifferent_access.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/core_ext/hash_with_indifferent_access.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/core_ext/ordered_hash.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/core_ext/ordered_hash.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/error.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/error.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/group.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/group.rb)2
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/invocation.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/invocation.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser/argument.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser/argument.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser/arguments.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser/arguments.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser/option.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser/option.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser/options.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser/options.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/rake_compat.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/rake_compat.rb)11
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/runner.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/runner.rb)2
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/shell.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/shell.rb)10
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/shell/basic.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/shell/basic.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/shell/color.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/shell/color.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/task.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/task.rb)0
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/util.rb (renamed from railties/lib/rails/vendor/thor-0.11.6/lib/thor/util.rb)4
-rw-r--r--railties/lib/rails/vendor/thor-0.12.0/lib/thor/version.rb3
-rw-r--r--railties/lib/rails/vendor_gem_source_index.rb140
100 files changed, 793 insertions, 1945 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index d54120f850..7c2d8eab67 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -1,8 +1,22 @@
module Rails
class Application
- extend Initializable
+ include Initializable
class << self
+ def inherited(klass)
+ Rails.application ||= klass unless klass.name =~ /Rails/
+ super
+ end
+
+ # Stub out App initialize
+ def initialize!
+ new
+ end
+
+ def new
+ @instance ||= super
+ end
+
def config
@config ||= Configuration.new
end
@@ -14,31 +28,52 @@ module Rails
@config = config
end
- def plugin_loader
- @plugin_loader ||= config.plugin_loader.new(self)
+ def root
+ config.root
end
- def routes
- ActionController::Routing::Routes
+ def call(env)
+ new.call(env)
end
+ end
- def middleware
- config.middleware
- end
+ def initialize
+ run_initializers(self)
+ end
- def call(env)
- @app ||= middleware.build(routes)
- @app.call(env)
- end
+ def config
+ self.class.config
+ end
- def new
- initializers.run
- self
+ alias configuration config
+
+ def middleware
+ config.middleware
+ end
+
+ def routes
+ ActionController::Routing::Routes
+ end
+
+ def initializers
+ initializers = super
+ plugins.each { |p| initializers += p.initializers }
+ initializers
+ end
+
+ def plugins
+ @plugins ||= begin
+ Plugin::Vendored.all(config.plugins || [:all], config.paths.vendor.plugins)
end
end
+ def call(env)
+ @app ||= middleware.build(routes)
+ @app.call(env)
+ end
+
initializer :initialize_rails do
- Rails.initializers.run
+ Rails.run_initializers
end
# Set the <tt>$LOAD_PATH</tt> based on the value of
@@ -48,13 +83,6 @@ module Rails
$LOAD_PATH.uniq!
end
- # Bail if boot.rb is outdated
- initializer :freak_out_if_boot_rb_is_outdated do
- unless defined?(Rails::BOOTSTRAP_VERSION)
- abort %{Your config/boot.rb is outdated: Run "rake rails:update".}
- end
- end
-
# Requires all frameworks specified by the Configuration#frameworks
# list. By default, all frameworks (Active Record, Active Support,
# Action Pack, Action Mailer, and Active Resource) are loaded.
@@ -92,17 +120,10 @@ module Rails
config.load_once_paths.freeze
end
- # Adds all load paths from plugins to the global set of load paths, so that
- # code from plugins can be required (explicitly or automatically via ActiveSupport::Dependencies).
- initializer :add_plugin_load_paths do
- require 'active_support/dependencies'
- plugin_loader.add_plugin_load_paths
- end
-
# Create tmp directories
initializer :ensure_tmp_directories_exist do
%w(cache pids sessions sockets).each do |dir_to_make|
- FileUtils.mkdir_p(File.join(config.root_path, 'tmp', dir_to_make))
+ FileUtils.mkdir_p(File.join(config.root, 'tmp', dir_to_make))
end
end
@@ -124,15 +145,6 @@ module Rails
end
end
- initializer :add_gem_load_paths do
- require 'rails/gem_dependency'
- Rails::GemDependency.add_frozen_gem_path
- unless config.gems.empty?
- require "rubygems"
- config.gems.each { |gem| gem.add_load_paths }
- end
- end
-
# Preload all frameworks specified by the Configuration#frameworks.
# Used by Passenger to ensure everything's loaded before forking and
# to avoid autoload race conditions in JRuby.
@@ -249,6 +261,7 @@ module Rails
# If assigned value cannot be matched to a TimeZone, an exception will be raised.
initializer :initialize_time_zone do
if config.time_zone
+ require 'active_support/core_ext/time/zones'
zone_default = Time.__send__(:get_zone, config.time_zone)
unless zone_default
@@ -310,7 +323,6 @@ module Rails
# TODO: Make Rails and metal work without ActionController
if config.frameworks.include?(:action_controller)
Rails::Rack::Metal.requested_metals = config.metals
- Rails::Rack::Metal.metal_paths += plugin_loader.engine_metal_paths
config.middleware.insert_before(
:"ActionDispatch::ParamsParser",
@@ -318,94 +330,19 @@ module Rails
end
end
- initializer :check_for_unbuilt_gems do
- unbuilt_gems = config.gems.select {|gem| gem.frozen? && !gem.built? }
- if unbuilt_gems.size > 0
- # don't print if the gems:build rake tasks are being run
- unless $gems_build_rake_task
- abort <<-end_error
- The following gems have native components that need to be built
- #{unbuilt_gems.map { |gemm| "#{gemm.name} #{gemm.requirement}" } * "\n "}
-
- You're running:
- ruby #{Gem.ruby_version} at #{Gem.ruby}
- rubygems #{Gem::RubyGemsVersion} at #{Gem.path * ', '}
-
- Run `rake gems:build` to build the unbuilt gems.
- end_error
- end
- end
- end
-
- initializer :load_gems do
- unless $gems_rake_task
- config.gems.each { |gem| gem.load }
- end
- end
-
- # Loads all plugins in <tt>config.plugin_paths</tt>. <tt>plugin_paths</tt>
- # defaults to <tt>vendor/plugins</tt> but may also be set to a list of
- # paths, such as
- # config.plugin_paths = ["#{RAILS_ROOT}/lib/plugins", "#{RAILS_ROOT}/vendor/plugins"]
- #
- # In the default implementation, as each plugin discovered in <tt>plugin_paths</tt> is initialized:
- # * its +lib+ directory, if present, is added to the load path (immediately after the applications lib directory)
- # * <tt>init.rb</tt> is evaluated, if present
- #
- # After all plugins are loaded, duplicates are removed from the load path.
- # If an array of plugin names is specified in config.plugins, only those plugins will be loaded
- # and they plugins will be loaded in that order. Otherwise, plugins are loaded in alphabetical
- # order.
- #
- # if config.plugins ends contains :all then the named plugins will be loaded in the given order and all other
- # plugins will be loaded in alphabetical order
- initializer :load_plugins do
- plugin_loader.load_plugins
- end
-
- # TODO: Figure out if this needs to run a second time
- # load_gems
-
- initializer :check_gem_dependencies do
- unloaded_gems = config.gems.reject { |g| g.loaded? }
- if unloaded_gems.size > 0
- configuration.gems_dependencies_loaded = false
- # don't print if the gems rake tasks are being run
- unless $gems_rake_task
- abort <<-end_error
- Missing these required gems:
- #{unloaded_gems.map { |gemm| "#{gemm.name} #{gemm.requirement}" } * "\n "}
-
- You're running:
- ruby #{Gem.ruby_version} at #{Gem.ruby}
- rubygems #{Gem::RubyGemsVersion} at #{Gem.path * ', '}
-
- Run `rake gems:install` to install the missing gems.
- end_error
- end
- else
- configuration.gems_dependencies_loaded = true
- end
- end
-
# # bail out if gems are missing - note that check_gem_dependencies will have
# # already called abort() unless $gems_rake_task is set
# return unless gems_dependencies_loaded
-
initializer :load_application_initializers do
- if config.gems_dependencies_loaded
- Dir["#{configuration.root_path}/config/initializers/**/*.rb"].sort.each do |initializer|
- load(initializer)
- end
+ Dir["#{configuration.root}/config/initializers/**/*.rb"].sort.each do |initializer|
+ load(initializer)
end
end
# Fires the user-supplied after_initialize block (Configuration#after_initialize)
initializer :after_initialize do
- if config.gems_dependencies_loaded
- configuration.after_initialize_blocks.each do |block|
- block.call
- end
+ configuration.after_initialize_blocks.each do |block|
+ block.call
end
end
@@ -447,7 +384,7 @@ module Rails
#
# # Observers are loaded after plugins in case Observers or observed models are modified by plugins.
initializer :load_observers do
- if config.gems_dependencies_loaded && configuration.frameworks.include?(:active_record)
+ if configuration.frameworks.include?(:active_record)
ActiveRecord::Base.instantiate_observers
end
end
@@ -473,14 +410,14 @@ module Rails
end
end
- # Configure generators if they were already loaded
- # ===
- # TODO: Does this need to be an initializer here?
- initializer :initialize_generators do
- if defined?(Rails::Generators)
- Rails::Generators.no_color! unless config.generators.colorize_logging
- Rails::Generators.aliases.deep_merge! config.generators.aliases
- Rails::Generators.options.deep_merge! config.generators.options
+ # For each framework, search for instrument file with Notifications hooks.
+ #
+ initializer :load_notifications_hooks do
+ config.frameworks.each do |framework|
+ begin
+ require "#{framework}/notifications"
+ rescue LoadError => e
+ end
end
end
end
diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb
index 9ff8367807..cd7dd0f80a 100644
--- a/railties/lib/rails/backtrace_cleaner.rb
+++ b/railties/lib/rails/backtrace_cleaner.rb
@@ -1,5 +1,4 @@
require 'active_support/backtrace_cleaner'
-require 'rails/gem_dependency'
module Rails
class BacktraceCleaner < ActiveSupport::BacktraceCleaner
@@ -18,7 +17,7 @@ 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
@@ -28,17 +27,14 @@ module Rails
add_silencer { |line| RAILS_GEMS.any? { |gem| line =~ /^#{gem} / } }
add_silencer { |line| line =~ %r(vendor/plugins/[^\/]+/lib) }
end
-
-
+
private
def add_gem_filters
+ return unless defined? Gem
(Gem.path + [Gem.default_dir]).uniq.each do |path|
# http://gist.github.com/30430
add_filter { |line| line.sub(/(#{path})\/gems\/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) \4')}
end
-
- vendor_gems_path = Rails::GemDependency.unpacked_path.sub("#{RAILS_ROOT}/",'')
- add_filter { |line| line.sub(/(#{vendor_gems_path})\/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) [v] \4')}
end
end
diff --git a/railties/lib/rails/commands/about.rb b/railties/lib/rails/commands/about.rb
index bc2cfcb948..d4c30bbeb2 100644
--- a/railties/lib/rails/commands/about.rb
+++ b/railties/lib/rails/commands/about.rb
@@ -1,3 +1,2 @@
-require "#{RAILS_ROOT}/config/environment"
require 'rails/info'
puts Rails::Info
diff --git a/railties/lib/rails/commands/console.rb b/railties/lib/rails/commands/console.rb
index 31448bdf1a..b977b7162f 100644
--- a/railties/lib/rails/commands/console.rb
+++ b/railties/lib/rails/commands/console.rb
@@ -12,7 +12,7 @@ OptionParser.new do |opt|
end
libs = " -r irb/completion"
-libs << %( -r "#{RAILS_ROOT}/config/environment")
+libs << %( -r "#{Rails.root}/config/environment")
libs << " -r rails/console_app"
libs << " -r rails/console_sandbox" if options[:sandbox]
libs << " -r rails/console_with_helpers"
diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb
index e6f11a45db..4e699acf6b 100644
--- a/railties/lib/rails/commands/dbconsole.rb
+++ b/railties/lib/rails/commands/dbconsole.rb
@@ -25,7 +25,7 @@ OptionParser.new do |opt|
end
env = ARGV.first || ENV['RAILS_ENV'] || 'development'
-unless config = YAML::load(ERB.new(IO.read(RAILS_ROOT + "/config/database.yml")).result)[env]
+unless config = YAML::load(ERB.new(IO.read(Rails.root + "/config/database.yml")).result)[env]
abort "No database is configured for the environment '#{env}'"
end
diff --git a/railties/lib/rails/commands/destroy.rb b/railties/lib/rails/commands/destroy.rb
index 5013d30b83..f85c17bb94 100644
--- a/railties/lib/rails/commands/destroy.rb
+++ b/railties/lib/rails/commands/destroy.rb
@@ -1,5 +1,5 @@
-require File.expand_path(File.join(File.dirname(__FILE__), '..', 'generators'))
-require "#{RAILS_ROOT}/config/environment"
+require 'rails/generators'
+Rails::Generators.configure!
if ARGV.size == 0
Rails::Generators.help
diff --git a/railties/lib/rails/commands/generate.rb b/railties/lib/rails/commands/generate.rb
index 32cabcab10..c5e3ae3529 100755
--- a/railties/lib/rails/commands/generate.rb
+++ b/railties/lib/rails/commands/generate.rb
@@ -1,5 +1,5 @@
-require File.expand_path(File.join(File.dirname(__FILE__), '..', 'generators'))
-require "#{RAILS_ROOT}/config/environment"
+require 'rails/generators'
+Rails::Generators.configure!
if ARGV.size == 0
Rails::Generators.help
diff --git a/railties/lib/rails/commands/performance/benchmarker.rb b/railties/lib/rails/commands/performance/benchmarker.rb
index e8804fe1bf..dfba4bf034 100644
--- a/railties/lib/rails/commands/performance/benchmarker.rb
+++ b/railties/lib/rails/commands/performance/benchmarker.rb
@@ -10,7 +10,6 @@ rescue ArgumentError
N = 1
end
-require RAILS_ROOT + '/config/environment'
require 'benchmark'
include Benchmark
@@ -21,4 +20,4 @@ bm(6) do |x|
ARGV.each_with_index do |expression, idx|
x.report("##{idx + 1}") { N.times { eval(expression) } }
end
-end
+end
diff --git a/railties/lib/rails/commands/performance/profiler.rb b/railties/lib/rails/commands/performance/profiler.rb
index 7df840f197..aaa075018c 100644
--- a/railties/lib/rails/commands/performance/profiler.rb
+++ b/railties/lib/rails/commands/performance/profiler.rb
@@ -3,10 +3,6 @@ if ARGV.empty?
exit(1)
end
-# Keep the expensive require out of the profile.
-$stderr.puts 'Loading Rails...'
-require RAILS_ROOT + '/config/environment'
-
# Define a method to profile.
if ARGV[1] and ARGV[1].to_i > 1
eval "def profile_me() #{ARGV[1]}.times { #{ARGV[0]} } end"
diff --git a/railties/lib/rails/commands/runner.rb b/railties/lib/rails/commands/runner.rb
index 510128318a..0246348c77 100644
--- a/railties/lib/rails/commands/runner.rb
+++ b/railties/lib/rails/commands/runner.rb
@@ -36,8 +36,6 @@ ARGV.delete(code_or_file)
ENV["RAILS_ENV"] = options[:environment]
RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV)
-require RAILS_ROOT + '/config/environment'
-
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 c138cbc9bf..2c90851fb2 100644
--- a/railties/lib/rails/commands/server.rb
+++ b/railties/lib/rails/commands/server.rb
@@ -1,4 +1,4 @@
-require 'action_controller'
+require 'action_dispatch'
require 'fileutils'
require 'optparse'
@@ -7,7 +7,7 @@ options = {
:Port => 3000,
:Host => "0.0.0.0",
:environment => (ENV['RAILS_ENV'] || "development").dup,
- :config => RAILS_ROOT + "/config.ru",
+ :config => "#{Rails.root}/config.ru",
:detach => false,
:debugger => false
}
@@ -42,11 +42,11 @@ unless server
end
puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}"
-puts "=> Rails #{Rails.version} application starting on http://#{options[:Host]}:#{options[:Port]}}"
+puts "=> Rails #{Rails.version} application starting on http://#{options[:Host]}:#{options[:Port]}"
if options[:detach]
Process.daemon
- pid = "#{RAILS_ROOT}/tmp/pids/server.pid"
+ pid = "#{Rails.root}/tmp/pids/server.pid"
File.open(pid, 'w'){ |f| f.write(Process.pid) }
at_exit { File.delete(pid) if File.exist?(pid) }
end
diff --git a/railties/lib/rails/commands/update.rb b/railties/lib/rails/commands/update.rb
index f3b3ad0775..85a81cddf0 100644
--- a/railties/lib/rails/commands/update.rb
+++ b/railties/lib/rails/commands/update.rb
@@ -1,5 +1,4 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'generators'))
-require "#{RAILS_ROOT}/config/environment"
if ARGV.size == 0
Rails::Generators.help
diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb
index 4a70a4800e..102a0836dc 100644
--- a/railties/lib/rails/configuration.rb
+++ b/railties/lib/rails/configuration.rb
@@ -1,84 +1,75 @@
+require 'active_support/ordered_options'
+
module Rails
class Configuration
- attr_accessor :cache_classes, :load_paths, :eager_load_paths, :framework_paths,
- :load_once_paths, :gems_dependencies_loaded, :after_initialize_blocks,
- :frameworks, :framework_root_path, :root_path, :plugin_paths, :plugins,
- :plugin_loader, :plugin_locators, :gems, :loaded_plugins, :reload_plugins,
+ attr_accessor :cache_classes, :load_paths, :load_once_paths, :after_initialize_blocks,
+ :frameworks, :framework_root_path, :root, :gems, :plugins,
:i18n, :gems, :whiny_nils, :consider_all_requests_local,
:action_controller, :active_record, :action_view, :active_support,
:action_mailer, :active_resource,
- :log_path, :log_level, :logger, :preload_frameworks,
+ :reload_plugins, :log_path, :log_level, :logger, :preload_frameworks,
:database_configuration_file, :cache_store, :time_zone,
:view_path, :metals, :controller_paths, :routes_configuration_file,
:eager_load_paths, :dependency_loading, :paths, :serve_static_assets
def initialize
- set_root_path!
-
- @framework_paths = []
@load_once_paths = []
@after_initialize_blocks = []
- @loaded_plugins = []
@dependency_loading = true
- @eager_load_paths = default_eager_load_paths
- @load_paths = default_load_paths
- @plugin_paths = default_plugin_paths
- @frameworks = default_frameworks
- @plugin_loader = default_plugin_loader
- @plugin_locators = default_plugin_locators
- @gems = default_gems
- @i18n = default_i18n
- @log_path = default_log_path
- @log_level = default_log_level
- @cache_store = default_cache_store
- @view_path = default_view_path
- @controller_paths = default_controller_paths
- @routes_configuration_file = default_routes_configuration_file
- @database_configuration_file = default_database_configuration_file
- @serve_static_assets = default_serve_static_assets
-
- for framework in default_frameworks
- self.send("#{framework}=", Rails::OrderedOptions.new)
+ @serve_static_assets = true
+
+ for framework in frameworks
+ self.send("#{framework}=", ActiveSupport::OrderedOptions.new)
end
- self.active_support = Rails::OrderedOptions.new
+ self.active_support = ActiveSupport::OrderedOptions.new
end
def after_initialize(&blk)
@after_initialize_blocks << blk if blk
end
- def set_root_path!
- raise 'RAILS_ROOT is not set' unless defined?(RAILS_ROOT)
- raise 'RAILS_ROOT is not a directory' unless File.directory?(RAILS_ROOT)
-
- self.root_path =
- # Pathname is incompatible with Windows, but Windows doesn't have
- # real symlinks so File.expand_path is safe.
- if RUBY_PLATFORM =~ /(:?mswin|mingw)/
- File.expand_path(RAILS_ROOT)
+ def root
+ @root ||= begin
+ call_stack = caller.map { |p| p.split(':').first }
+ root_path = call_stack.detect { |p| p !~ %r[railties/lib/rails] }
+ root_path = File.dirname(root_path)
- # Otherwise use Pathname#realpath which respects symlinks.
- else
- Pathname.new(RAILS_ROOT).realpath.to_s
+ while root_path && File.directory?(root_path) && !File.exist?("#{root_path}/config.ru")
+ parent = File.dirname(root_path)
+ root_path = parent != root_path && parent
end
- @paths = Rails::Application::Root.new(root_path)
- @paths.app "app", :load_path => true
- @paths.app.metals "app/metal", :eager_load => true
- @paths.app.models "app/models", :eager_load => true
- @paths.app.controllers "app/controllers", builtin_directories, :eager_load => true
- @paths.app.helpers "app/helpers", :eager_load => true
- @paths.app.services "app/services", :load_path => true
- @paths.lib "lib", :load_path => true
- @paths.vendor "vendor", :load_path => true
- @paths.vendor.plugins "vendor/plugins"
- @paths.tmp "tmp"
- @paths.tmp.cache "tmp/cache"
- @paths.config "config"
- @paths.config.locales "config/locales"
- @paths.config.environments "config/environments", :glob => "#{RAILS_ENV}.rb"
-
- RAILS_ROOT.replace root_path
+ root = File.exist?("#{root_path}/config.ru") ? root_path : Dir.pwd
+
+ RUBY_PLATFORM =~ /(:?mswin|mingw)/ ?
+ Pathname.new(root).expand_path :
+ Pathname.new(root).realpath
+ end
+ end
+
+ def root=(root)
+ @root = Pathname.new(root).expand_path
+ end
+
+ def paths
+ @paths ||= begin
+ paths = Rails::Application::Root.new(root)
+ paths.app "app", :load_path => true
+ paths.app.metals "app/metal", :eager_load => true
+ paths.app.models "app/models", :eager_load => true
+ paths.app.controllers "app/controllers", builtin_directories, :eager_load => true
+ paths.app.helpers "app/helpers", :eager_load => true
+ paths.app.services "app/services", :load_path => true
+ paths.lib "lib", :load_path => true
+ paths.vendor "vendor", :load_path => true
+ paths.vendor.plugins "vendor/plugins"
+ paths.tmp "tmp"
+ paths.tmp.cache "tmp/cache"
+ paths.config "config"
+ paths.config.locales "config/locales"
+ paths.config.environments "config/environments", :glob => "#{RAILS_ENV}.rb"
+ paths
+ end
end
# Enable threaded mode. Allows concurrent requests to controller actions and
@@ -105,7 +96,7 @@ module Rails
end
def framework_root_path
- defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{root_path}/vendor/rails"
+ defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{root}/vendor/rails"
end
def middleware
@@ -121,63 +112,69 @@ module Rails
YAML::load(ERB.new(IO.read(database_configuration_file)).result)
end
- def default_routes_configuration_file
- File.join(root_path, 'config', 'routes.rb')
+ def routes_configuration_file
+ @routes_configuration_file ||= File.join(root, 'config', 'routes.rb')
end
- def default_controller_paths
- paths = [File.join(root_path, 'app', 'controllers')]
- paths.concat builtin_directories
- paths
+ def controller_paths
+ @controller_paths ||= begin
+ paths = [File.join(root, 'app', 'controllers')]
+ paths.concat builtin_directories
+ paths
+ end
end
- def default_cache_store
- if File.exist?("#{root_path}/tmp/cache/")
- [ :file_store, "#{root_path}/tmp/cache/" ]
- else
- :memory_store
+ def cache_store
+ @cache_store ||= begin
+ if File.exist?("#{root}/tmp/cache/")
+ [ :file_store, "#{root}/tmp/cache/" ]
+ else
+ :memory_store
+ end
end
end
- def default_database_configuration_file
- File.join(root_path, 'config', 'database.yml')
+ def database_configuration_file
+ @database_configuration_file ||= File.join(root, 'config', 'database.yml')
end
- def default_view_path
- File.join(root_path, 'app', 'views')
+ def view_path
+ @view_path ||= File.join(root, 'app', 'views')
end
- def default_eager_load_paths
- %w(
+ def eager_load_paths
+ @eager_load_paths ||= %w(
app/metal
app/models
app/controllers
app/helpers
- ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
+ ).map { |dir| "#{root}/#{dir}" }.select { |dir| File.directory?(dir) }
end
- def default_load_paths
- paths = []
-
- # Add the old mock paths only if the directories exists
- paths.concat(Dir["#{root_path}/test/mocks/#{RAILS_ENV}"]) if File.exists?("#{root_path}/test/mocks/#{RAILS_ENV}")
-
- # Add the app's controller directory
- paths.concat(Dir["#{root_path}/app/controllers/"])
-
- # Followed by the standard includes.
- paths.concat %w(
- app
- app/metal
- app/models
- app/controllers
- app/helpers
- app/services
- lib
- vendor
- ).map { |dir| "#{root_path}/#{dir}" }.select { |dir| File.directory?(dir) }
-
- paths.concat builtin_directories
+ def load_paths
+ @load_paths ||= begin
+ paths = []
+
+ # Add the old mock paths only if the directories exists
+ paths.concat(Dir["#{root}/test/mocks/#{RAILS_ENV}"]) if File.exists?("#{root}/test/mocks/#{RAILS_ENV}")
+
+ # Add the app's controller directory
+ paths.concat(Dir["#{root}/app/controllers/"])
+
+ # Followed by the standard includes.
+ paths.concat %w(
+ app
+ app/metal
+ app/models
+ app/controllers
+ app/helpers
+ app/services
+ lib
+ vendor
+ ).map { |dir| "#{root}/#{dir}" }.select { |dir| File.directory?(dir) }
+
+ paths.concat builtin_directories
+ end
end
def builtin_directories
@@ -185,75 +182,34 @@ module Rails
(RAILS_ENV == 'development') ? Dir["#{RAILTIES_PATH}/builtin/*/"] : []
end
- def default_log_path
- File.join(root_path, 'log', "#{RAILS_ENV}.log")
+ def log_path
+ @log_path ||= File.join(root, 'log', "#{RAILS_ENV}.log")
end
- def default_log_level
- RAILS_ENV == 'production' ? :info : :debug
+ def log_level
+ @log_level ||= RAILS_ENV == 'production' ? :info : :debug
end
- def default_frameworks
- [ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ]
+ def frameworks
+ @frameworks ||= [ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ]
end
- def default_plugin_paths
- ["#{root_path}/vendor/plugins"]
- end
-
- def default_plugin_loader
- require 'rails/plugin/loader'
- Plugin::Loader
- end
+ def i18n
+ @i18n ||= begin
+ i18n = ActiveSupport::OrderedOptions.new
+ i18n.load_path = []
- def default_plugin_locators
- require 'rails/plugin/locator'
- locators = []
- locators << Plugin::GemLocator if defined? Gem
- locators << Plugin::FileSystemLocator
- end
-
- def default_i18n
- i18n = Rails::OrderedOptions.new
- i18n.load_path = []
+ if File.exist?(File.join(root, 'config', 'locales'))
+ i18n.load_path << Dir[File.join(root, 'config', 'locales', '*.{rb,yml}')]
+ i18n.load_path.flatten!
+ end
- if File.exist?(File.join(RAILS_ROOT, 'config', 'locales'))
- i18n.load_path << Dir[File.join(RAILS_ROOT, 'config', 'locales', '*.{rb,yml}')]
- i18n.load_path.flatten!
+ i18n
end
-
- i18n
- end
-
- def default_serve_static_assets
- true
- end
-
- # Adds a single Gem dependency to the rails application. By default, it will require
- # the library with the same name as the gem. Use :lib to specify a different name.
- #
- # # gem 'aws-s3', '>= 0.4.0'
- # # require 'aws/s3'
- # config.gem 'aws-s3', :lib => 'aws/s3', :version => '>= 0.4.0', \
- # :source => "http://code.whytheluckystiff.net"
- #
- # To require a library be installed, but not attempt to load it, pass :lib => false
- #
- # config.gem 'qrp', :version => '0.4.1', :lib => false
- def gem(name, options = {})
- @gems << Rails::GemDependency.new(name, options)
- end
-
- def default_gems
- []
end
def environment_path
- "#{root_path}/config/environments/#{RAILS_ENV}.rb"
- end
-
- def reload_plugins?
- @reload_plugins
+ "#{root}/config/environments/#{RAILS_ENV}.rb"
end
# Holds generators configuration:
@@ -277,6 +233,14 @@ module Rails
end
end
+ # Allows Notifications queue to be modified.
+ #
+ # config.notifications.queue = MyNewQueue.new
+ #
+ def notifications
+ ActiveSupport::Notifications
+ end
+
class Generators #:nodoc:
attr_accessor :aliases, :options, :colorize_logging
@@ -287,12 +251,16 @@ module Rails
end
def method_missing(method, *args)
- method = method.to_s.sub(/=$/, '').to_sym
- namespace = args.first.is_a?(Symbol) ? args.shift : nil
- configuration = args.first.is_a?(Hash) ? args.shift : nil
+ method = method.to_s.sub(/=$/, '').to_sym
- @options[:rails][method] = namespace if namespace
- namespace ||= method
+ if method == :rails
+ namespace, configuration = :rails, args.shift
+ elsif args.first.is_a?(Hash)
+ namespace, configuration = method, args.shift
+ else
+ namespace, configuration = args.shift, args.shift
+ @options[:rails][method] = namespace
+ end
if configuration
aliases = configuration.delete(:aliases)
diff --git a/railties/lib/rails/core.rb b/railties/lib/rails/core.rb
index 929c38bd22..a5e51ad04a 100644
--- a/railties/lib/rails/core.rb
+++ b/railties/lib/rails/core.rb
@@ -6,7 +6,7 @@ module Rails
# TODO: w0t?
class << self
def application
- @@application
+ @@application ||= nil
end
def application=(application)
@@ -18,6 +18,10 @@ module Rails
application.configuration
end
+ def initialize!
+ application.initialize!
+ end
+
def initialized?
@initialized || false
end
@@ -43,7 +47,7 @@ module Rails
end
def root
- Pathname.new(RAILS_ROOT) if defined?(RAILS_ROOT)
+ application && application.config.root
end
def env
@@ -66,36 +70,4 @@ module Rails
@@public_path = path
end
end
-
- class OrderedOptions < Array #:nodoc:
- def []=(key, value)
- key = key.to_sym
-
- if pair = find_pair(key)
- pair.pop
- pair << value
- else
- self << [key, value]
- end
- end
-
- def [](key)
- pair = find_pair(key.to_sym)
- pair ? pair.last : nil
- end
-
- def method_missing(name, *args)
- if name.to_s =~ /(.*)=$/
- self[$1.to_sym] = args.first
- else
- self[name]
- end
- end
-
- private
- def find_pair(key)
- self.each { |i| return i if i.first == key }
- return false
- end
- end
end \ No newline at end of file
diff --git a/railties/lib/rails/deprecation.rb b/railties/lib/rails/deprecation.rb
new file mode 100644
index 0000000000..3c5b8bdec7
--- /dev/null
+++ b/railties/lib/rails/deprecation.rb
@@ -0,0 +1,25 @@
+require "active_support/string_inquirer"
+require "active_support/deprecation"
+
+RAILS_ROOT = (Class.new(ActiveSupport::Deprecation::DeprecationProxy) do
+ def target
+ Rails.root
+ end
+
+ def replace(val)
+ puts OMG
+ end
+
+ def warn(callstack, called, args)
+ msg = "RAILS_ROOT is deprecated! Use Rails.root instead."
+ ActiveSupport::Deprecation.warn(msg, callstack)
+ end
+end).new
+
+module Rails
+ class Configuration
+ def gem(*args)
+ ActiveSupport::Deprecation.warn("config.gem has been deprecated in favor of the Gemfile.")
+ end
+ end
+end \ No newline at end of file
diff --git a/railties/lib/rails/gem_builder.rb b/railties/lib/rails/gem_builder.rb
deleted file mode 100644
index 79c61cc034..0000000000
--- a/railties/lib/rails/gem_builder.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require 'rubygems'
-require 'rubygems/installer'
-
-module Rails
-
- # this class hijacks the functionality of Gem::Installer by overloading its
- # initializer to only provide the information needed by
- # Gem::Installer#build_extensions (which happens to be what we have)
- class GemBuilder < Gem::Installer
-
- def initialize(spec, gem_dir)
- @spec = spec
- @gem_dir = gem_dir
- end
-
- # silence the underlying builder
- def say(message)
- end
-
- end
-end
diff --git a/railties/lib/rails/gem_dependency.rb b/railties/lib/rails/gem_dependency.rb
deleted file mode 100644
index 06d830ba24..0000000000
--- a/railties/lib/rails/gem_dependency.rb
+++ /dev/null
@@ -1,311 +0,0 @@
-require 'rails/vendor_gem_source_index'
-
-module Gem
- def self.source_index=(index)
- @@source_index = index
- end
-end
-
-module Rails
- class GemDependency < Gem::Dependency
- attr_accessor :lib, :source, :dep
-
- def self.unpacked_path
- @unpacked_path ||= File.join(RAILS_ROOT, 'vendor', 'gems')
- end
-
- @@framework_gems = {}
-
- def self.add_frozen_gem_path
- @@paths_loaded ||= begin
- source_index = Rails::VendorGemSourceIndex.new(Gem.source_index)
- Gem.clear_paths
- Gem.source_index = source_index
- # loaded before us - we can't change them, so mark them
- Gem.loaded_specs.each do |name, spec|
- @@framework_gems[name] = spec
- end
- true
- end
- end
-
- def self.from_directory_name(directory_name, load_spec=true)
- directory_name_parts = File.basename(directory_name).split('-')
- name = directory_name_parts[0..-2].join('-')
- version = directory_name_parts.last
- result = self.new(name, :version => version)
- spec_filename = File.join(directory_name, '.specification')
- if load_spec
- raise "Missing specification file in #{File.dirname(spec_filename)}. Perhaps you need to do a 'rake gems:refresh_specs'?" unless File.exists?(spec_filename)
- spec = YAML::load_file(spec_filename)
- result.specification = spec
- end
- result
- rescue ArgumentError => e
- raise "Unable to determine gem name and version from '#{directory_name}'"
- end
-
- def initialize(name, options = {})
- require 'rubygems' unless Object.const_defined?(:Gem)
-
- if options[:requirement]
- req = options[:requirement]
- elsif options[:version]
- req = Gem::Requirement.create(options[:version])
- else
- req = Gem::Requirement.default
- end
-
- @lib = options[:lib]
- @source = options[:source]
- @loaded = @frozen = @load_paths_added = false
-
- super(name, req)
- end
-
- def add_load_paths
- self.class.add_frozen_gem_path
- return if @loaded || @load_paths_added
- if framework_gem?
- @load_paths_added = @loaded = @frozen = true
- return
- end
- gem self
- @spec = Gem.loaded_specs[name]
- @frozen = @spec.loaded_from.include?(self.class.unpacked_path) if @spec
- @load_paths_added = true
- rescue Gem::LoadError
- end
-
- def dependencies
- return [] if framework_gem?
- return [] unless installed?
- specification.dependencies.reject do |dependency|
- dependency.type == :development
- end.map do |dependency|
- GemDependency.new(dependency.name, :requirement => dependency.version_requirements)
- end
- end
-
- def specification
- # code repeated from Gem.activate. Find a matching spec, or the currently loaded version.
- # error out if loaded version and requested version are incompatible.
- @spec ||= begin
- matches = Gem.source_index.search(self)
- matches << @@framework_gems[name] if framework_gem?
- if Gem.loaded_specs[name] then
- # This gem is already loaded. If the currently loaded gem is not in the
- # list of candidate gems, then we have a version conflict.
- existing_spec = Gem.loaded_specs[name]
- unless matches.any? { |spec| spec.version == existing_spec.version } then
- raise Gem::Exception,
- "can't activate #{@dep}, already activated #{existing_spec.full_name}"
- end
- # we're stuck with it, so change to match
- version_requirements = Gem::Requirement.create("=#{existing_spec.version}")
- existing_spec
- else
- # new load
- matches.last
- end
- end
- end
-
- def specification=(s)
- @spec = s
- end
-
- def requirement
- r = version_requirements
- (r == Gem::Requirement.default) ? nil : r
- end
-
- def built?
- return false unless frozen?
-
- if vendor_gem?
- specification.extensions.each do |ext|
- makefile = File.join(unpacked_gem_directory, File.dirname(ext), 'Makefile')
- return false unless File.exists?(makefile)
- end
- end
-
- true
- end
-
- def framework_gem?
- @@framework_gems.has_key?(name)
- end
-
- def frozen?
- @frozen ||= vendor_rails? || vendor_gem?
- end
-
- def installed?
- Gem.loaded_specs.keys.include?(name)
- end
-
- def load_paths_added?
- # always try to add load paths - even if a gem is loaded, it may not
- # be a compatible version (ie random_gem 0.4 is loaded and a later spec
- # needs >= 0.5 - gem 'random_gem' will catch this and error out)
- @load_paths_added
- end
-
- def loaded?
- @loaded ||= begin
- if vendor_rails?
- true
- elsif specification.nil?
- false
- else
- # check if the gem is loaded by inspecting $"
- # specification.files lists all the files contained in the gem
- gem_files = specification.files
- # select only the files contained in require_paths - typically in bin and lib
- require_paths_regexp = Regexp.new("^(#{specification.require_paths*'|'})/")
- gem_lib_files = gem_files.select { |f| require_paths_regexp.match(f) }
- # chop the leading directory off - a typical file might be in
- # lib/gem_name/file_name.rb, but it will be 'require'd as gem_name/file_name.rb
- gem_lib_files.map! { |f| f.split('/', 2)[1] }
- # if any of the files from the above list appear in $", the gem is assumed to
- # have been loaded
- !(gem_lib_files & $").empty?
- end
- end
- end
-
- def vendor_rails?
- Gem.loaded_specs.has_key?(name) && Gem.loaded_specs[name].loaded_from.empty?
- end
-
- def vendor_gem?
- specification && File.exists?(unpacked_gem_directory)
- end
-
- def build(options={})
- require 'rails/gem_builder'
- return if specification.nil?
- if options[:force] || !built?
- return unless File.exists?(unpacked_specification_filename)
- spec = YAML::load_file(unpacked_specification_filename)
- Rails::GemBuilder.new(spec, unpacked_gem_directory).build_extensions
- puts "Built gem: '#{unpacked_gem_directory}'"
- end
- dependencies.each { |dep| dep.build(options) }
- end
-
- def install
- unless installed?
- cmd = "#{gem_command} #{install_command.join(' ')}"
- puts cmd
- puts %x(#{cmd})
- end
- end
-
- def load
- return if @loaded || @load_paths_added == false
- require(@lib || name) unless @lib == false
- @loaded = true
- rescue LoadError
- puts $!.to_s
- $!.backtrace.each { |b| puts b }
- end
-
- def refresh
- Rails::VendorGemSourceIndex.silence_spec_warnings = true
- real_gems = Gem.source_index.installed_source_index
- exact_dep = Gem::Dependency.new(name, "= #{specification.version}")
- matches = real_gems.search(exact_dep)
- installed_spec = matches.first
- if frozen?
- if installed_spec
- # we have a real copy
- # get a fresh spec - matches should only have one element
- # note that there is no reliable method to check that the loaded
- # spec is the same as the copy from real_gems - Gem.activate changes
- # some of the fields
- real_spec = Gem::Specification.load(matches.first.loaded_from)
- write_specification(real_spec)
- puts "Reloaded specification for #{name} from installed gems."
- else
- # the gem isn't installed locally - write out our current specs
- write_specification(specification)
- puts "Gem #{name} not loaded locally - writing out current spec."
- end
- else
- if framework_gem?
- puts "Gem directory for #{name} not found - check if it's loading before rails."
- else
- puts "Something bad is going on - gem directory not found for #{name}."
- end
- end
- end
-
- def unpack(options={})
- unless frozen? || framework_gem?
- FileUtils.mkdir_p unpack_base
- Dir.chdir unpack_base do
- Gem::GemRunner.new.run(unpack_command)
- end
- # Gem.activate changes the spec - get the original
- real_spec = Gem::Specification.load(specification.loaded_from)
- write_specification(real_spec)
- end
- dependencies.each { |dep| dep.unpack(options) } if options[:recursive]
- end
-
- def write_specification(spec)
- # copy the gem's specification into GEMDIR/.specification so that
- # we can access information about the gem on deployment systems
- # without having the gem installed
- File.open(unpacked_specification_filename, 'w') do |file|
- file.puts spec.to_yaml
- end
- end
-
- def ==(other)
- self.name == other.name && self.requirement == other.requirement
- end
- alias_method :"eql?", :"=="
-
- private
-
- def gem_command
- case RUBY_PLATFORM
- when /win32/
- 'gem.bat'
- when /java/
- 'jruby -S gem'
- else
- 'gem'
- end
- end
-
- def install_command
- cmd = %w(install) << name
- cmd << "--version" << %("#{requirement.to_s}") if requirement
- cmd << "--source" << @source if @source
- cmd
- end
-
- def unpack_command
- cmd = %w(unpack) << name
- cmd << "--version" << "= "+specification.version.to_s if requirement
- cmd
- end
-
- def unpack_base
- Rails::GemDependency.unpacked_path
- end
-
- def unpacked_gem_directory
- File.join(unpack_base, specification.full_name)
- end
-
- def unpacked_specification_filename
- File.join(unpacked_gem_directory, '.specification')
- end
-
- end
-end
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index 0419a4e36c..19412c259e 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -1,4 +1,4 @@
-activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib"
+activesupport_path = "#{File.dirname(__FILE__)}/../../../activesupport/lib"
$LOAD_PATH.unshift(activesupport_path) if File.directory?(activesupport_path)
require 'active_support'
require 'active_support/core_ext/object/blank'
@@ -9,7 +9,7 @@ require 'active_support/core_ext/module/attribute_accessors'
require 'active_support/core_ext/string/inflections'
# TODO: Do not always push on vendored thor
-$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/vendor/thor-0.11.6/lib")
+$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/vendor/thor-0.12.0/lib")
require 'rails/generators/base'
require 'rails/generators/named_base'
@@ -72,6 +72,12 @@ module Rails
}
}
+ def self.configure!(config = Rails.application.config.generators) #:nodoc:
+ no_color! unless config.colorize_logging
+ aliases.deep_merge! config.aliases
+ options.deep_merge! config.options
+ end
+
def self.aliases #:nodoc:
@aliases ||= DEFAULT_ALIASES.dup
end
@@ -92,8 +98,6 @@ module Rails
generator_path = File.join(spec.full_gem_path, "lib/generators")
paths << generator_path if File.exist?(generator_path)
end
- elsif defined?(RAILS_ROOT)
- paths += Dir[File.join(RAILS_ROOT, "vendor", "gems", "gems", "*", "lib", "generators")]
end
paths
@@ -102,8 +106,8 @@ module Rails
# Load paths from plugin.
#
def self.plugins_generators_paths
- return [] unless defined?(RAILS_ROOT)
- Dir[File.join(RAILS_ROOT, "vendor", "plugins", "*", "lib", "generators")]
+ return [] unless Rails.root
+ Dir[File.join(Rails.root, "vendor", "plugins", "*", "lib", "generators")]
end
# Hold configured generators fallbacks. If a plugin developer wants a
@@ -143,7 +147,7 @@ module Rails
def self.load_paths
@load_paths ||= begin
paths = []
- paths << File.join(RAILS_ROOT, "lib", "generators") if defined?(RAILS_ROOT)
+ paths << File.join(Rails.root, "lib", "generators") if Rails.root
paths << File.join(Thor::Util.user_home, ".rails", "generators")
paths += self.plugins_generators_paths
paths += self.gems_generators_paths
@@ -154,7 +158,18 @@ module Rails
end
load_paths # Cache load paths. Needed to avoid __FILE__ pointing to wrong paths.
- # Receives a namespace and tries different combinations to find a generator.
+ # Rails finds namespaces exactly as thor, with three conveniences:
+ #
+ # 1) If your generator name ends with generator, as WebratGenerator, it sets
+ # its namespace to "webrat", so it can be invoked as "webrat" and not
+ # "webrat_generator";
+ #
+ # 2) If your generator has a generators namespace, as Rails::Generators::WebratGenerator,
+ # the namespace is set to "rails:generators:webrat", but Rails allows it
+ # to be invoked simply as "rails:webrat". The "generators" is added
+ # automatically when doing the lookup;
+ #
+ # 3) Rails looks in load paths and loads the generator just before it's going to be used.
#
# ==== Examples
#
@@ -164,30 +179,29 @@ module Rails
#
# "rails:generators:webrat", "webrat:generators:integration", "webrat"
#
- # If the namespace has ":" included we consider that a absolute namespace
- # was given and the lookup above does not happen. Just the name is searched.
+ # On the other hand, if "rails:webrat" is given, it will search for:
#
- # Finally, it deals with one kind of shortcut:
+ # "rails:generators:webrat", "rails:webrat"
#
- # find_by_namespace "test_unit:model"
- #
- # It will search for generators at:
- #
- # "test_unit:generators:model", "test_unit:model"
+ # Notice that the "generators" namespace is handled automatically by Rails,
+ # so you don't need to type it when you want to invoke a generator in specific.
#
def self.find_by_namespace(name, base=nil, context=nil) #:nodoc:
- name, attempts = name.to_s, []
+ name, attempts = name.to_s, [ ]
case name.count(':')
when 1
base, name = name.split(':')
return find_by_namespace(name, base)
when 0
- attempts << "#{base}:generators:#{name}" if base
- attempts << "#{name}:generators:#{context}" if context
+ attempts += generator_names(base, name) if base
+ attempts += generator_names(name, context) if context
end
attempts << name
+ attempts += generator_names(name, name) unless name.include?(?:)
+ attempts.uniq!
+
unloaded = attempts - namespaces
lookup(unloaded)
@@ -233,7 +247,10 @@ module Rails
until tail.empty?
others += Dir[File.join(path, *tail)].collect do |file|
- file.split('/')[-tail.size, 2].join(':').sub(/_generator\.rb$/, '')
+ name = file.split('/')[-tail.size, 2]
+ name.last.sub!(/_generator\.rb$/, '')
+ name.uniq!
+ name.join(':')
end
tail.shift
end
@@ -248,7 +265,7 @@ module Rails
# Return all defined namespaces.
#
def self.namespaces #:nodoc:
- Thor::Base.subclasses.map{ |klass| klass.namespace }
+ Thor::Base.subclasses.map { |klass| klass.namespace }
end
# Keep builtin generators in an Array[Array[group, name]].
@@ -259,6 +276,12 @@ module Rails
end
end
+ # By default, Rails strips the generator namespace to make invocations
+ # easier. This method generaters the both possibilities names.
+ def self.generator_names(first, second)
+ [ "#{first}:generators:#{second}", "#{first}:#{second}" ]
+ end
+
# Try callbacks for the given base.
#
def self.invoke_fallbacks_for(name, base)
@@ -287,6 +310,9 @@ module Rails
Dir[File.join(path, '**', attempts)].each do |file|
begin
require file
+ rescue NameError => e
+ raise unless e.message =~ /Rails::Generator/
+ warn "[WARNING] Could not load generator at #{file.inspect} because it's a Rails 2.x generator, which is not supported anymore"
rescue Exception => e
warn "[WARNING] Could not load generator at #{file.inspect}. Error: #{e.message}"
end
diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb
index c4552dd399..8677bf283b 100644
--- a/railties/lib/rails/generators/actions.rb
+++ b/railties/lib/rails/generators/actions.rb
@@ -1,4 +1,5 @@
require 'open-uri'
+require 'active_support/deprecation'
module Rails
module Generators
@@ -45,19 +46,56 @@ module Rails
#
# gem "rspec", :env => :test
# gem "technoweenie-restful-authentication", :lib => "restful-authentication", :source => "http://gems.github.com/"
+ # gem "rails", "3.0", :git => "git://github.com/rails/rails"
#
- def gem(name, options={})
- log :gem, name
- env = options.delete(:env)
+ def gem(*args)
+ options = args.extract_options!
+ name, version = args
- gems_code = "config.gem '#{name}'"
+ # Deal with deprecated options
+ { :env => :only, :lib => :require_as }.each do |old, new|
+ next unless options[old]
+ options[new] = options.delete(old)
+ ActiveSupport::Deprecation.warn "#{old.inspect} option in gem is deprecated, use #{new.inspect} instead"
+ end
+
+ # Deal with deprecated source
+ if source = options.delete(:source)
+ ActiveSupport::Deprecation.warn ":source option in gem is deprecated, use add_source method instead"
+ add_source(source)
+ end
+
+ # Set the message to be shown in logs. Uses the git repo if one is given,
+ # otherwise use name (version).
+ parts, message = [ name.inspect ], name
+ if version ||= options.delete(:version)
+ parts << version
+ message << " (#{version})"
+ end
+ message = options[:git] if options[:git]
+
+ log :gemfile, message
+
+ options.each do |option, value|
+ parts << ":#{option} => #{value.inspect}"
+ end
- if options.any?
- opts = options.inject([]) {|result, h| result << [":#{h[0]} => #{h[1].inspect.gsub('"',"'")}"] }.sort.join(", ")
- gems_code << ", #{opts}"
+ in_root do
+ append_file "Gemfile", "gem #{parts.join(", ")}", :verbose => false
end
+ end
+
+ # Add the given source to Gemfile
+ #
+ # ==== Example
+ #
+ # source "http://gems.github.com/"
+ def add_source(source, options={})
+ log :source, source
- environment gems_code, :env => env
+ in_root do
+ prepend_file "Gemfile", "source #{source.inspect}", :verbose => false
+ end
end
# Adds a line inside the Initializer block for config/environment.rb.
@@ -71,7 +109,7 @@ module Rails
in_root do
if options[:env].nil?
- inject_into_file 'config/environment.rb', "\n #{data}", :after => sentinel, :verbose => false
+ inject_into_file 'config/application.rb', "\n #{data}", :after => sentinel, :verbose => false
else
Array.wrap(options[:env]).each do|env|
append_file "config/environments/#{env}.rb", "\n#{data}", :verbose => false
@@ -79,6 +117,7 @@ module Rails
end
end
end
+ alias :application :environment
# Run a command in git.
#
@@ -222,9 +261,8 @@ module Rails
#
# freeze!
#
- def freeze!(args = {})
- log :vendor, "rails"
- in_root { run("#{extify(:rake)} rails:freeze:edge", :verbose => false) }
+ def freeze!(args={})
+ ActiveSupport::Deprecation.warn "freeze! is deprecated since your rails app now comes bundled with Rails by default, please check your Gemfile"
end
# Make an entry in Rails routing file conifg/routes.rb
@@ -251,6 +289,7 @@ module Rails
if args.size == 1
say args.first.to_s
else
+ args << (self.behavior == :invoke ? :green : :red)
say_status *args
end
end
diff --git a/railties/lib/rails/generators/active_model.rb b/railties/lib/rails/generators/active_model.rb
index 1a849a0e02..fe6321af30 100644
--- a/railties/lib/rails/generators/active_model.rb
+++ b/railties/lib/rails/generators/active_model.rb
@@ -32,7 +32,7 @@ module Rails
# GET index
def self.all(klass)
- raise NotImplementedError
+ "#{klass}.all"
end
# GET show
@@ -40,34 +40,38 @@ module Rails
# PUT update
# DELETE destroy
def self.find(klass, params=nil)
- raise NotImplementedError
+ "#{klass}.find(#{params})"
end
# GET new
# POST create
def self.build(klass, params=nil)
- raise NotImplementedError
+ if params
+ "#{klass}.new(#{params})"
+ else
+ "#{klass}.new"
+ end
end
# POST create
def save
- raise NotImplementedError
+ "#{name}.save"
end
# PUT update
def update_attributes(params=nil)
- raise NotImplementedError
+ "#{name}.update_attributes(#{params})"
end
# POST create
# PUT update
def errors
- raise NotImplementedError
+ "#{name}.errors"
end
# DELETE destroy
def destroy
- raise NotImplementedError
+ "#{name}.destroy"
end
end
end
diff --git a/railties/lib/rails/generators/active_record.rb b/railties/lib/rails/generators/active_record.rb
index c03ea59c1b..c62f75c384 100644
--- a/railties/lib/rails/generators/active_record.rb
+++ b/railties/lib/rails/generators/active_record.rb
@@ -1,6 +1,7 @@
require 'rails/generators/named_base'
require 'rails/generators/migration'
require 'rails/generators/active_model'
+require 'active_record'
module ActiveRecord
module Generators
@@ -18,39 +19,5 @@ module ActiveRecord
end
end
end
-
- class ActiveModel < Rails::Generators::ActiveModel #:nodoc:
- def self.all(klass)
- "#{klass}.all"
- end
-
- def self.find(klass, params=nil)
- "#{klass}.find(#{params})"
- end
-
- def self.build(klass, params=nil)
- if params
- "#{klass}.new(#{params})"
- else
- "#{klass}.new"
- end
- end
-
- def save
- "#{name}.save"
- end
-
- def update_attributes(params=nil)
- "#{name}.update_attributes(#{params})"
- end
-
- def errors
- "#{name}.errors"
- end
-
- def destroy
- "#{name}.destroy"
- end
- end
end
end
diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb
index 720caa5b3f..226ae63963 100644
--- a/railties/lib/rails/generators/base.rb
+++ b/railties/lib/rails/generators/base.rb
@@ -12,11 +12,24 @@ module Rails
add_runtime_options!
+ # Always move to rails source root.
+ #
+ def initialize(*args) #:nodoc:
+ if !invoked?(args) && defined?(Rails.root) && Rails.root
+ self.destination_root = Rails.root
+ FileUtils.cd(destination_root)
+ end
+ super
+ end
+
# Automatically sets the source root based on the class name.
#
def self.source_root
- @_rails_source_root ||= File.expand_path(File.join(File.dirname(__FILE__),
- base_name, generator_name, 'templates'))
+ @_rails_source_root ||= begin
+ if base_name && generator_name
+ File.expand_path(File.join(File.dirname(__FILE__), base_name, generator_name, 'templates'))
+ end
+ end
end
# Tries to get the description from a USAGE file one folder above the source
@@ -201,10 +214,13 @@ module Rails
#
def self.inherited(base) #:nodoc:
super
- base.source_root # Cache source root
- if defined?(RAILS_ROOT) && base.name !~ /Base$/
- path = File.expand_path(File.join(RAILS_ROOT, 'lib', 'templates'))
+ # Cache source root, we need to do this, since __FILE__ is a relative value
+ # and can point to wrong directions when inside an specified directory.
+ base.source_root
+
+ if base.name && base.name !~ /Base$/ && base.base_name && base.generator_name && defined?(Rails.root) && Rails.root
+ path = File.expand_path(File.join(Rails.root, 'lib', 'templates'))
if base.name.include?('::')
base.source_paths << File.join(path, base.base_name, base.generator_name)
else
@@ -247,6 +263,13 @@ module Rails
end
end
+ # Check if this generator was invoked from another one by inspecting
+ # parameters.
+ #
+ def invoked?(args)
+ args.last.is_a?(Hash) && args.last.key?(:invocations)
+ end
+
# Use Rails default banner.
#
def self.banner
@@ -256,17 +279,24 @@ module Rails
# Sets the base_name taking into account the current class namespace.
#
def self.base_name
- @base_name ||= self.name.split('::').first.underscore
+ @base_name ||= begin
+ if base = name.to_s.split('::').first
+ base.underscore
+ end
+ end
end
# Removes the namespaces and get the generator name. For example,
# Rails::Generators::MetalGenerator will return "metal" as generator name.
#
def self.generator_name
- @generator_name ||= begin
- klass_name = self.name.split('::').last
- klass_name.sub!(/Generator$/, '')
- klass_name.underscore
+ if name
+ @generator_name ||= begin
+ if klass_name = name.to_s.split('::').last
+ klass_name.sub!(/Generator$/, '')
+ klass_name.underscore
+ end
+ end
end
end
@@ -274,35 +304,27 @@ module Rails
# Rails::Generators.options.
#
def self.default_value_for_option(name, options)
- config = Rails::Generators.options
- generator, base = generator_name.to_sym, base_name.to_sym
-
- if config[generator] && config[generator].key?(name)
- config[generator][name]
- elsif config[base] && config[base].key?(name)
- config[base][name]
- elsif config[:rails].key?(name)
- config[:rails][name]
- else
- options[:default]
- end
+ default_for_option(Rails::Generators.options, name, options, options[:default])
end
# Return default aliases for the option name given doing a lookup in
# Rails::Generators.aliases.
#
def self.default_aliases_for_option(name, options)
- config = Rails::Generators.aliases
- generator, base = generator_name.to_sym, base_name.to_sym
+ default_for_option(Rails::Generators.aliases, name, options, options[:aliases])
+ end
- if config[generator] && config[generator].key?(name)
- config[generator][name]
- elsif config[base] && config[base].key?(name)
- config[base][name]
+ # Return default for the option name given doing a lookup in config.
+ #
+ def self.default_for_option(config, name, options, default)
+ if generator_name and c = config[generator_name.to_sym] and c.key?(name)
+ c[name]
+ elsif base_name and c = config[base_name.to_sym] and c.key?(name)
+ c[name]
elsif config[:rails].key?(name)
config[:rails][name]
else
- options[:aliases]
+ default
end
end
diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb
index 0e5976f915..1d4f52286e 100644
--- a/railties/lib/rails/generators/named_base.rb
+++ b/railties/lib/rails/generators/named_base.rb
@@ -11,7 +11,10 @@ module Rails
alias :file_name :singular_name
- def initialize(*args) #:nodoc:
+ def initialize(args, *options) #:nodoc:
+ # Unfreeze name in case it's given as a frozen string
+ args[0] = args[0].dup if args[0].is_a?(String) && args[0].frozen?
+
super
assign_names!(self.name)
parse_attributes! if respond_to?(:attributes)
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb
index 78b4b057ae..2bcea4bc8f 100644
--- a/railties/lib/rails/generators/rails/app/app_generator.rb
+++ b/railties/lib/rails/generators/rails/app/app_generator.rb
@@ -1,4 +1,4 @@
-require 'digest/md5'
+require 'digest/md5'
require 'active_support/secure_random'
require 'rails/version' unless defined?(Rails::VERSION)
@@ -12,9 +12,6 @@ module Rails::Generators
class_option :database, :type => :string, :aliases => "-d", :default => "sqlite3",
:desc => "Preconfigure for selected database (options: #{DATABASES.join('/')})"
- class_option :freeze, :type => :boolean, :aliases => "-F", :default => false,
- :desc => "Freeze Rails in vendor/rails from the gems"
-
class_option :template, :type => :string, :aliases => "-m",
:desc => "Path to an application template (can be a filesystem path or URL)."
@@ -54,6 +51,7 @@ module Rails::Generators
copy_file "Rakefile"
copy_file "README"
copy_file "config.ru"
+ template "Gemfile"
end
def create_app_files
@@ -65,6 +63,7 @@ module Rails::Generators
inside "config" do
copy_file "routes.rb"
+ template "application.rb"
template "environment.rb"
directory "environments"
@@ -124,8 +123,10 @@ module Rails::Generators
end
def create_script_files
- directory "script"
- chmod "script", 0755, :verbose => false
+ directory "script" do |file|
+ prepend_file file, "#{shebang}\n", :verbose => false
+ chmod file, 0755, :verbose => false
+ end
end
def create_test_files
@@ -153,10 +154,6 @@ module Rails::Generators
raise Error, "The template [#{rails_template}] could not be loaded. Error: #{e}"
end
- def freeze?
- freeze! if options[:freeze]
- end
-
protected
attr_accessor :rails_template
diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile
new file mode 100644
index 0000000000..8e851a64e7
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/Gemfile
@@ -0,0 +1,18 @@
+# Edit this Gemfile to bundle your application's dependencies.
+
+gem "rails", "<%= Rails::VERSION::STRING %>"
+
+## Bundle edge rails:
+# gem "rails", :git => "git://github.com/rails/rails.git"
+
+## Bundle the gems you use:
+# gem "bj"
+# gem "hpricot", "0.6"
+# gem "sqlite3-ruby", :require_as => "sqlite3"
+# gem "aws-s3", :require_as => "aws/s3"
+
+## Bundle gems used only in certain environments:
+# gem "rspec", :only => :test
+# only :test do
+# gem "webrat"
+# end
diff --git a/railties/lib/rails/generators/rails/app/templates/Rakefile b/railties/lib/rails/generators/rails/app/templates/Rakefile
index bd4dec5389..6b6d07e8cc 100755
--- a/railties/lib/rails/generators/rails/app/templates/Rakefile
+++ b/railties/lib/rails/generators/rails/app/templates/Rakefile
@@ -1,7 +1,7 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
-require(File.join(File.dirname(__FILE__), 'config', 'boot'))
+require File.expand_path('../config/application', __FILE__)
require 'rake'
require 'rake/testtask'
diff --git a/railties/lib/rails/generators/rails/app/templates/config.ru b/railties/lib/rails/generators/rails/app/templates/config.ru
index 50ee033d44..509a0da5b7 100644
--- a/railties/lib/rails/generators/rails/app/templates/config.ru
+++ b/railties/lib/rails/generators/rails/app/templates/config.ru
@@ -1,5 +1,5 @@
# Require your environment file to bootstrap Rails
-require ::File.dirname(__FILE__) + '/config/environment'
+require ::File.expand_path('../config/environment', __FILE__)
# Dispatch the request
-run Rails.application.new
+run Rails.application
diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb
new file mode 100644
index 0000000000..8008c6ba07
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb
@@ -0,0 +1,41 @@
+require File.expand_path('../boot', __FILE__)
+
+Rails::Initializer.run do |config|
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+
+ # Add additional load paths for your own custom dirs
+ # config.load_paths += %W( #{root}/extras )
+
+ # Only load the plugins named here, in the order given (default is alphabetical).
+ # :all can be used as a placeholder for all plugins not explicitly named
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
+ # Skip frameworks you're not going to use. To use Rails without a database,
+ # you must remove the Active Record framework.
+<% if options[:skip_activerecord] -%>
+ config.frameworks -= [ :active_record ]
+<% else -%>
+ # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
+
+ # Activate observers that should always be running
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
+<% end -%>
+
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+ # Run "rake -D time" for a list of tasks for finding time zone names.
+ config.time_zone = 'UTC'
+
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
+ # config.i18n.default_locale = :de
+
+ # Configure generators values. Many other options are available, be sure to
+ # check the documentation.
+ # config.generators do |g|
+ # g.orm :active_record
+ # g.template_engine :erb
+ # g.test_framework :test_unit, :fixture => true
+ # end
+end
diff --git a/railties/lib/rails/generators/rails/app/templates/config/boot.rb b/railties/lib/rails/generators/rails/app/templates/config/boot.rb
index 6e0e2279cd..5aa49ca5e6 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/boot.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/boot.rb
@@ -1,148 +1,16 @@
-# Don't change this file!
-# Configure your app in config/environment.rb and config/environments/*.rb
-
-RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
-
-module Rails
- # Mark the version of Rails that generated the boot.rb file. This is
- # a temporary solution and will most likely be removed as Rails 3.0
- # comes closer.
- BOOTSTRAP_VERSION = "3.0"
-
- class << self
- def boot!
- unless booted?
- preinitialize
- pick_boot.run
- end
- end
-
- def booted?
- defined? Rails::Initializer
- end
-
- def pick_boot
- (vendor_rails? ? VendorBoot : GemBoot).new
- end
-
- def vendor_rails?
- File.exist?("#{RAILS_ROOT}/vendor/rails")
- end
-
- def preinitialize
- load(preinitializer_path) if File.exist?(preinitializer_path)
- end
-
- def preinitializer_path
- "#{RAILS_ROOT}/config/preinitializer.rb"
- end
- end
-
- class Boot
- def run
- set_load_paths
- load_initializer
- end
-
- def set_load_paths
- %w(
- actionmailer/lib
- actionpack/lib
- activemodel/lib
- activerecord/lib
- activeresource/lib
- activesupport/lib
- railties/lib
- railties
- ).reverse_each do |path|
- path = "#{framework_root_path}/#{path}"
- $LOAD_PATH.unshift(path) if File.directory?(path)
- $LOAD_PATH.uniq!
- end
- end
-
- def framework_root_path
- defined?(::RAILS_FRAMEWORK_ROOT) ? ::RAILS_FRAMEWORK_ROOT : "#{RAILS_ROOT}/vendor/rails"
- end
+# Use Bundler (preferred)
+environment = File.expand_path('../../vendor/gems/environment', __FILE__)
+if File.exist?("#{environment}.rb")
+ require environment
+
+# Use 2.x style vendor/rails and RubyGems
+else
+ vendor_rails = File.expand_path('../../vendor/rails', __FILE__)
+ if File.exist?(vendor_rails)
+ Dir["#{vendor_rails}/*/lib"].each { |path| $:.unshift(path) }
end
- class VendorBoot < Boot
- def load_initializer
- require "rails"
- install_gem_spec_stubs
- Rails::GemDependency.add_frozen_gem_path
- end
-
- def install_gem_spec_stubs
- begin; require "rubygems"; rescue LoadError; return; end
-
- %w(rails activesupport activerecord actionpack actionmailer activeresource).each do |stub|
- Gem.loaded_specs[stub] ||= Gem::Specification.new do |s|
- s.name = stub
- s.version = Rails::VERSION::STRING
- s.loaded_from = ""
- end
- end
- end
- end
-
- class GemBoot < Boot
- def load_initializer
- self.class.load_rubygems
- load_rails_gem
- require 'rails'
- end
-
- def load_rails_gem
- if version = self.class.gem_version
- gem 'rails', version
- else
- gem 'rails'
- end
- rescue Gem::LoadError => load_error
- $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
- exit 1
- end
-
- class << self
- def rubygems_version
- Gem::RubyGemsVersion rescue nil
- end
-
- def gem_version
- if defined? RAILS_GEM_VERSION
- RAILS_GEM_VERSION
- elsif ENV.include?('RAILS_GEM_VERSION')
- ENV['RAILS_GEM_VERSION']
- else
- parse_gem_version(read_environment_rb)
- end
- end
-
- def load_rubygems
- min_version = '1.3.2'
- require 'rubygems'
- unless rubygems_version >= min_version
- $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
- exit 1
- end
-
- rescue LoadError
- $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
- exit 1
- end
-
- def parse_gem_version(text)
- $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
- end
-
- private
- def read_environment_rb
- File.read("#{RAILS_ROOT}/config/environment.rb")
- end
- end
- end
+ require 'rubygems'
end
-# All that for this:
-Rails.boot!
+require 'rails'
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environment.rb b/railties/lib/rails/generators/rails/app/templates/config/environment.rb
index adb3a3060a..0bb191f205 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environment.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/environment.rb
@@ -1,53 +1,5 @@
-# Be sure to restart your server when you modify this file
+# Load the rails application
+require File.expand_path('../application', __FILE__)
-# Specifies gem version of Rails to use when vendor/rails is not present
-<%= '# ' if options[:freeze] %>RAILS_GEM_VERSION = '<%= Rails::VERSION::STRING %>' unless defined? RAILS_GEM_VERSION
-
-# Bootstrap the Rails environment, frameworks, and default configuration
-require File.join(File.dirname(__FILE__), 'boot')
-
-Rails::Initializer.run do |config|
- # Settings in config/environments/* take precedence over those specified here.
- # Application configuration should go into files in config/initializers
- # -- all .rb files in that directory are automatically loaded.
-
- # Add additional load paths for your own custom dirs
- # config.load_paths += %W( #{RAILS_ROOT}/extras )
-
- # Specify gems that this application depends on and have them installed with rake gems:install
- # config.gem "bj"
- # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
- # config.gem "sqlite3-ruby", :lib => "sqlite3"
- # config.gem "aws-s3", :lib => "aws/s3"
-
- # Only load the plugins named here, in the order given (default is alphabetical).
- # :all can be used as a placeholder for all plugins not explicitly named
- # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
-
- # Skip frameworks you're not going to use. To use Rails without a database,
- # you must remove the Active Record framework.
-<% if options[:skip_activerecord] -%>
- config.frameworks -= [ :active_record ]
-<% else -%>
- # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
-
- # Activate observers that should always be running
- # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
-<% end -%>
-
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
- # Run "rake -D time" for a list of tasks for finding time zone names.
- config.time_zone = 'UTC'
-
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
- # config.i18n.default_locale = :de
-
- # Configure generators values. Many other options are available, be sure to
- # check the documentation.
- # config.generators do |g|
- # g.orm :active_record
- # g.template_engine :erb
- # g.test_framework :test_unit, :fixture => true
- # end
-end
+# Initialize the rails application
+Rails.initialize!
diff --git a/railties/lib/rails/generators/rails/app/templates/script/about.tt b/railties/lib/rails/generators/rails/app/templates/script/about
index 1220676c08..93fd007649 100755
--- a/railties/lib/rails/generators/rails/app/templates/script/about.tt
+++ b/railties/lib/rails/generators/rails/app/templates/script/about
@@ -1,4 +1,3 @@
-<%= shebang %>
-require File.expand_path('../../config/boot', __FILE__)
+require File.expand_path('../../config/environment', __FILE__)
$LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
require 'rails/commands/about'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/console b/railties/lib/rails/generators/rails/app/templates/script/console
new file mode 100755
index 0000000000..20aa799d2f
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/script/console
@@ -0,0 +1,2 @@
+require File.expand_path('../../config/application', __FILE__)
+require 'rails/commands/console'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/console.tt b/railties/lib/rails/generators/rails/app/templates/script/console.tt
deleted file mode 100755
index 5aec193853..0000000000
--- a/railties/lib/rails/generators/rails/app/templates/script/console.tt
+++ /dev/null
@@ -1,3 +0,0 @@
-<%= shebang %>
-require File.expand_path('../../config/boot', __FILE__)
-require 'rails/commands/console'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/dbconsole b/railties/lib/rails/generators/rails/app/templates/script/dbconsole
new file mode 100755
index 0000000000..e6a1c59394
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/script/dbconsole
@@ -0,0 +1,2 @@
+require File.expand_path('../../config/application', __FILE__)
+require 'rails/commands/dbconsole'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/dbconsole.tt b/railties/lib/rails/generators/rails/app/templates/script/dbconsole.tt
deleted file mode 100755
index 632563f470..0000000000
--- a/railties/lib/rails/generators/rails/app/templates/script/dbconsole.tt
+++ /dev/null
@@ -1,3 +0,0 @@
-<%= shebang %>
-require File.expand_path('../../config/boot', __FILE__)
-require 'rails/commands/dbconsole'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/destroy b/railties/lib/rails/generators/rails/app/templates/script/destroy
new file mode 100755
index 0000000000..adfa8e8426
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/script/destroy
@@ -0,0 +1,2 @@
+require File.expand_path('../../config/environment', __FILE__)
+require 'rails/commands/destroy'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/destroy.tt b/railties/lib/rails/generators/rails/app/templates/script/destroy.tt
deleted file mode 100755
index c5f94862c3..0000000000
--- a/railties/lib/rails/generators/rails/app/templates/script/destroy.tt
+++ /dev/null
@@ -1,3 +0,0 @@
-<%= shebang %>
-require File.expand_path('../../config/boot', __FILE__)
-require 'rails/commands/destroy'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/generate b/railties/lib/rails/generators/rails/app/templates/script/generate
new file mode 100755
index 0000000000..6fb8ad0395
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/script/generate
@@ -0,0 +1,2 @@
+require File.expand_path('../../config/environment', __FILE__)
+require 'rails/commands/generate'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/generate.tt b/railties/lib/rails/generators/rails/app/templates/script/generate.tt
deleted file mode 100755
index d466c94767..0000000000
--- a/railties/lib/rails/generators/rails/app/templates/script/generate.tt
+++ /dev/null
@@ -1,3 +0,0 @@
-<%= shebang %>
-require File.expand_path('../../config/boot', __FILE__)
-require 'rails/commands/generate'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/performance/benchmarker b/railties/lib/rails/generators/rails/app/templates/script/performance/benchmarker
new file mode 100755
index 0000000000..9647d8f10a
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/script/performance/benchmarker
@@ -0,0 +1,2 @@
+require File.expand_path('../../../config/environment', __FILE__)
+require 'rails/commands/performance/benchmarker'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/performance/benchmarker.tt b/railties/lib/rails/generators/rails/app/templates/script/performance/benchmarker.tt
deleted file mode 100755
index 3e03aaa767..0000000000
--- a/railties/lib/rails/generators/rails/app/templates/script/performance/benchmarker.tt
+++ /dev/null
@@ -1,3 +0,0 @@
-<%= shebang %>
-require File.expand_path('../../../config/boot', __FILE__)
-require 'rails/commands/performance/benchmarker'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/performance/profiler b/railties/lib/rails/generators/rails/app/templates/script/performance/profiler
new file mode 100755
index 0000000000..a5822042d2
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/script/performance/profiler
@@ -0,0 +1,2 @@
+require File.expand_path('../../../config/environment', __FILE__)
+require 'rails/commands/performance/profiler'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/performance/profiler.tt b/railties/lib/rails/generators/rails/app/templates/script/performance/profiler.tt
deleted file mode 100755
index deada2f561..0000000000
--- a/railties/lib/rails/generators/rails/app/templates/script/performance/profiler.tt
+++ /dev/null
@@ -1,3 +0,0 @@
-<%= shebang %>
-require File.expand_path('../../../config/boot', __FILE__)
-require 'rails/commands/performance/profiler'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/plugin b/railties/lib/rails/generators/rails/app/templates/script/plugin
new file mode 100755
index 0000000000..1f1af6c880
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/script/plugin
@@ -0,0 +1,2 @@
+require File.expand_path('../../config/application', __FILE__)
+require 'rails/commands/plugin'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/plugin.tt b/railties/lib/rails/generators/rails/app/templates/script/plugin.tt
deleted file mode 100755
index f4081f56b6..0000000000
--- a/railties/lib/rails/generators/rails/app/templates/script/plugin.tt
+++ /dev/null
@@ -1,3 +0,0 @@
-<%= shebang %>
-require File.expand_path('../../config/boot', __FILE__)
-require 'rails/commands/plugin'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/runner b/railties/lib/rails/generators/rails/app/templates/script/runner
new file mode 100755
index 0000000000..7a70828e90
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/script/runner
@@ -0,0 +1,2 @@
+require File.expand_path('../../config/environment', __FILE__)
+require 'rails/commands/runner'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/runner.tt b/railties/lib/rails/generators/rails/app/templates/script/runner.tt
deleted file mode 100755
index 60c8c0bba1..0000000000
--- a/railties/lib/rails/generators/rails/app/templates/script/runner.tt
+++ /dev/null
@@ -1,3 +0,0 @@
-<%= shebang %>
-require File.expand_path('../../config/boot', __FILE__)
-require 'rails/commands/runner'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/server b/railties/lib/rails/generators/rails/app/templates/script/server
new file mode 100755
index 0000000000..a7aaee2953
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/script/server
@@ -0,0 +1,2 @@
+require File.expand_path('../../config/application', __FILE__)
+require 'rails/commands/server'
diff --git a/railties/lib/rails/generators/rails/app/templates/script/server.tt b/railties/lib/rails/generators/rails/app/templates/script/server.tt
deleted file mode 100755
index 54e3346bec..0000000000
--- a/railties/lib/rails/generators/rails/app/templates/script/server.tt
+++ /dev/null
@@ -1,3 +0,0 @@
-<%= shebang %>
-require File.expand_path('../../config/boot', __FILE__)
-require 'rails/commands/server'
diff --git a/railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb b/railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb
index 4b60558b43..a3dc38d9e4 100644
--- a/railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb
+++ b/railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb
@@ -1,5 +1,5 @@
require 'test_helper'
-require 'performance_test_help'
+require 'rails/performance_test_help'
# Profiling results for each test method are written to tmp/performance.
class BrowsingTest < ActionController::PerformanceTest
diff --git a/railties/lib/rails/generators/resource_helpers.rb b/railties/lib/rails/generators/resource_helpers.rb
index d4b0d4b945..99954e2292 100644
--- a/railties/lib/rails/generators/resource_helpers.rb
+++ b/railties/lib/rails/generators/resource_helpers.rb
@@ -1,9 +1,13 @@
+require 'rails/generators/active_model'
+
module Rails
module Generators
# Deal with controller names on scaffold and add some helpers to deal with
# ActiveModel.
#
module ResourceHelpers
+ mattr_accessor :skip_warn
+
def self.included(base) #:nodoc:
base.send :attr_reader, :controller_name, :controller_class_name, :controller_file_name,
:controller_class_path, :controller_file_path
@@ -17,7 +21,11 @@ module Rails
super
if name == name.pluralize && !options[:force_plural]
- say "Plural version of the model detected, using singularized version. Override with --force-plural."
+ unless ResourceHelpers.skip_warn
+ say "Plural version of the model detected, using singularized version. Override with --force-plural."
+ ResourceHelpers.skip_warn = true
+ end
+
name.replace name.singularize
assign_names!(self.name)
end
@@ -47,20 +55,11 @@ module Rails
raise "You need to have :orm as class option to invoke orm_class and orm_instance"
end
- active_model = "#{options[:orm].to_s.classify}::Generators::ActiveModel"
-
- # If the orm was not loaded, try to load it at "generators/orm",
- # for example "generators/active_record" or "generators/sequel".
begin
- klass = active_model.constantize
- rescue NameError
- require "rails/generators/#{options[:orm]}"
+ "#{options[:orm].to_s.classify}::Generators::ActiveModel".constantize
+ rescue NameError => e
+ Rails::Generators::ActiveModel
end
-
- # Try once again after loading the file with success.
- klass ||= active_model.constantize
- rescue Exception => e
- raise Error, "Could not load #{active_model}, skipping controller. Error: #{e.message}."
end
end
diff --git a/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb b/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb
index 27c91b0fca..362e3dc09f 100644
--- a/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb
+++ b/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb
@@ -1,5 +1,5 @@
require 'test_helper'
-require 'performance_test_help'
+require 'rails/performance_test_help'
class <%= class_name %>Test < ActionController::PerformanceTest
# Replace this with your real tests.
diff --git a/railties/lib/rails/initializable.rb b/railties/lib/rails/initializable.rb
index 4bd5088207..3866b856b2 100644
--- a/railties/lib/rails/initializable.rb
+++ b/railties/lib/rails/initializable.rb
@@ -1,85 +1,117 @@
module Rails
module Initializable
+ def self.included(base)
+ base.extend ClassMethods
+ end
- # A collection of initializers
- class Collection
- def initialize(context)
- @context = context
- @keys = []
- @values = {}
- @ran = false
- end
+ class Initializer
+ attr_reader :name, :before, :after, :global, :block
- def run
- return self if @ran
- each do |key, initializer|
- @context.class_eval(&initializer.block)
- end
- @ran = true
- self
+ def initialize(name, context, options, &block)
+ @name, @context, @options, @block = name, context, options, block
end
- def [](key)
- keys, values = merge_with_parent
- values[key.to_sym]
+ def before
+ @options[:before]
end
- def []=(key, value)
- key = key.to_sym
- @keys |= [key]
- @values[key] = value
+ def after
+ @options[:after]
end
- def each
- keys, values = merge_with_parent
- keys.each { |k| yield k, values[k] }
- self
+ def global
+ @options[:global]
end
- protected
-
- attr_reader :keys, :values
+ alias global? global
- private
+ def run(*args)
+ @context.instance_exec(*args, &block)
+ end
- def merge_with_parent
- keys, values = [], {}
+ def bind(context)
+ return self if @context
+ Initializer.new(@name, context, @options, &block)
+ end
+ end
- if @context.is_a?(Class) && @context.superclass.is_a?(Initializable)
- parent = @context.superclass.initializers
- keys, values = parent.keys, parent.values
+ class Collection < Array
+ def initialize(initializers = [])
+ super()
+ initializers.each do |initializer|
+ if initializer.before
+ index = index_for(initializer.before)
+ elsif initializer.after
+ index = index_for(initializer.after)
+ index += 1 if index
+ else
+ index = length
+ end
+ insert(index || -1, initializer)
end
-
- values = values.merge(@values)
- return keys | @keys, values
end
- end
-
- class Initializer
- attr_reader :name, :options, :block
+ def +(other)
+ Collection.new(to_a + other.to_a)
+ end
- def initialize(name, options = {}, &block)
- @name, @options, @block = name, options, block
+ def index_for(name)
+ initializer = find { |i| i.name == name }
+ initializer && index(initializer)
end
end
- def initializer(name, options = {}, &block)
- @initializers ||= Collection.new(self)
- @initializers[name] = Initializer.new(name, options, &block)
+ def run_initializers(*args)
+ return if @ran
+ initializers.each do |initializer|
+ initializer.run(*args)
+ end
+ @ran = true
end
def initializers
- @initializers ||= Collection.new(self)
+ @initializers ||= begin
+ initializers = self.class.initializers_for(:instance)
+ Collection.new(initializers.map { |i| i.bind(self) })
+ end
end
+ module ClassMethods
+ def initializers
+ @initializers ||= []
+ end
+
+ def initializers_for(scope = :global)
+ initializers = Collection.new
+ ancestors.reverse_each do |klass|
+ next unless klass.respond_to?(:initializers)
+ initializers = initializers + klass.initializers.select { |i|
+ (scope == :global) == !!i.global?
+ }
+ end
+ initializers
+ end
+
+ def initializer(name, opts = {}, &blk)
+ @initializers ||= []
+ @initializers << Initializer.new(name, nil, opts, &blk)
+ end
+
+ def run_initializers(*args)
+ return if @ran
+ initializers_for(:global).each do |initializer|
+ instance_exec(*args, &initializer.block)
+ end
+ @ran = true
+ end
+ end
end
- extend Initializable
+ include Initializable
# Check for valid Ruby version (1.8.2 or 1.8.4 or higher). This is done in an
# external file, so we can use it from the `rails` program as well without duplication.
- initializer :check_ruby_version do
+ initializer :check_ruby_version, :global => true do
require 'rails/ruby_version_check'
end
@@ -89,7 +121,7 @@ module Rails
# on ActionController::Base.
#
# For Ruby 1.9, UTF-8 is the default internal and external encoding.
- initializer :initialize_encoding do
+ initializer :initialize_encoding, :global => true do
if RUBY_VERSION < '1.9'
$KCODE='u'
else
diff --git a/railties/lib/rails/initializer.rb b/railties/lib/rails/initializer.rb
index f7c3774450..44d04688c8 100644
--- a/railties/lib/rails/initializer.rb
+++ b/railties/lib/rails/initializer.rb
@@ -1,14 +1,4 @@
-require "pathname"
-
-require 'rails/initializable'
-require 'rails/application'
-require 'rails/railties_path'
-require 'rails/version'
-require 'rails/gem_dependency'
-require 'rails/rack'
-require 'rails/paths'
-require 'rails/core'
-require 'rails/configuration'
+require "rails" # In case people require this file directly
RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
@@ -21,8 +11,7 @@ module Rails
else
Rails.application = Class.new(Application)
yield Rails.application.config if block_given?
- Rails.application.new
end
end
end
-end
+end \ No newline at end of file
diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb
index 3899b744b0..b3d105d8c7 100644
--- a/railties/lib/rails/paths.rb
+++ b/railties/lib/rails/paths.rb
@@ -19,14 +19,14 @@ module Rails
class Root
include PathParent
- attr_reader :path
+ attr_accessor :path
+
def initialize(path)
- raise unless path.is_a?(String)
+ raise if path.is_a?(Array)
@children = {}
- # TODO: Move logic from set_root_path initializer
- @path = File.expand_path(path)
+ @path = path
@root = self
@all_paths = []
end
@@ -64,7 +64,7 @@ module Rails
end
class Path
- include PathParent
+ include PathParent, Enumerable
attr_reader :path
attr_accessor :glob
@@ -83,6 +83,10 @@ module Rails
@root.all_paths << self
end
+ def each
+ to_a.each { |p| yield p }
+ end
+
def push(path)
@paths.push path
end
@@ -123,8 +127,10 @@ module Rails
end
def paths
+ raise "You need to set a path root" unless @root.path
+
@paths.map do |path|
- path.index('/') == 0 ? path : File.join(@root.path, path)
+ path.index('/') == 0 ? path : File.expand_path(File.join(@root.path, path))
end
end
diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb
index 1c0af6411a..86bf032641 100644
--- a/railties/lib/rails/plugin.rb
+++ b/railties/lib/rails/plugin.rb
@@ -1,180 +1,64 @@
module Rails
- # The Plugin class should be an object which provides the following methods:
- #
- # * +name+ - Used during initialisation to order the plugin (based on name and
- # the contents of <tt>config.plugins</tt>).
- # * +valid?+ - Returns true if this plugin can be loaded.
- # * +load_paths+ - Each path within the returned array will be added to the <tt>$LOAD_PATH</tt>.
- # * +load+ - Finally 'load' the plugin.
- #
- # These methods are expected by the Rails::Plugin::Locator and Rails::Plugin::Loader classes.
- # The default implementation returns the <tt>lib</tt> directory as its <tt>load_paths</tt>,
- # and evaluates <tt>init.rb</tt> when <tt>load</tt> is called.
- #
- # You can also inspect the about.yml data programmatically:
- #
- # plugin = Rails::Plugin.new(path_to_my_plugin)
- # plugin.about["author"] # => "James Adam"
- # plugin.about["url"] # => "http://interblah.net"
class Plugin
- include Comparable
-
- attr_reader :directory, :name
-
- def initialize(directory)
- @directory = directory
- @name = File.basename(@directory) rescue nil
- @loaded = false
- end
-
- def valid?
- File.directory?(directory) && (has_app_directory? || has_lib_directory? || has_init_file?)
- end
-
- # Returns a list of paths this plugin wishes to make available in <tt>$LOAD_PATH</tt>.
- def load_paths
- report_nonexistant_or_empty_plugin! unless valid?
-
- load_paths = []
- load_paths << lib_path if has_lib_directory?
- load_paths << app_paths if has_app_directory?
- load_paths.flatten
- end
-
- # Evaluates a plugin's init.rb file.
- def load(initializer)
- return if loaded?
- report_nonexistant_or_empty_plugin! unless valid?
- evaluate_init_rb(initializer)
- @loaded = true
- end
-
- def loaded?
- @loaded
- end
-
- def <=>(other_plugin)
- name <=> other_plugin.name
- end
-
- def about
- @about ||= load_about_information
- end
-
- # Engines are plugins with an app/ directory.
- def engine?
- has_app_directory?
- end
-
- # Returns true if the engine ships with a routing file
- def routed?
- File.exist?(routing_file)
- end
-
- # Returns true if there is any localization file in locale_path
- def localized?
- locale_files.any?
- end
-
- def view_path
- File.join(directory, 'app', 'views')
- end
-
- def controller_path
- File.join(directory, 'app', 'controllers')
- end
-
- def metal_path
- File.join(directory, 'app', 'metal')
- end
-
- def routing_file
- File.join(directory, 'config', 'routes.rb')
- end
-
- def locale_path
- File.join(directory, 'config', 'locales')
- end
-
- def locale_files
- Dir[ File.join(locale_path, '*.{rb,yml}') ]
- end
-
+ include Initializable
+
+ class Vendored < Plugin
+ def self.all(list, paths)
+ plugins = []
+ paths.each do |path|
+ Dir["#{path}/*"].each do |plugin_path|
+ plugin = new(plugin_path)
+ next unless list.include?(plugin.name) || list.include?(:all)
+ plugins << plugin
+ end
+ end
- private
- def load_about_information
- about_yml_path = File.join(@directory, "about.yml")
- parsed_yml = File.exist?(about_yml_path) ? YAML.load(File.read(about_yml_path)) : {}
- parsed_yml || {}
- rescue Exception
- {}
+ plugins.sort_by do |p|
+ [list.index(p.name) || list.index(:all), p.name.to_s]
+ end
end
- def report_nonexistant_or_empty_plugin!
- raise LoadError, "Can not find the plugin named: #{name}"
- end
+ attr_reader :name, :path
-
- def app_paths
- [ File.join(directory, 'app', 'models'), File.join(directory, 'app', 'helpers'), controller_path, metal_path ]
- end
-
- def lib_path
- File.join(directory, 'lib')
+ def initialize(path)
+ @name = File.basename(path).to_sym
+ @path = path
end
- def classic_init_path
- File.join(directory, 'init.rb')
+ def load_paths
+ Dir["#{path}/{lib}", "#{path}/app/{models,controllers,helpers}"]
end
- def gem_init_path
- File.join(directory, 'rails', 'init.rb')
- end
+ initializer :add_to_load_path, :after => :set_autoload_paths do |app|
+ load_paths.each do |path|
+ $LOAD_PATH << path
+ require "active_support/dependencies"
- def init_path
- File.file?(gem_init_path) ? gem_init_path : classic_init_path
- end
+ ActiveSupport::Dependencies.load_paths << path
-
- def has_app_directory?
- File.directory?(File.join(directory, 'app'))
+ unless app.config.reload_plugins
+ ActiveSupport::Dependencies.load_once_paths << path
+ end
+ end
end
- def has_lib_directory?
- File.directory?(lib_path)
+ initializer :load_init_rb, :before => :load_application_initializers do |app|
+ file = "#{@path}/init.rb"
+ config = app.config
+ eval File.read(file), binding, file if File.file?(file)
end
- def has_init_file?
- File.file?(init_path)
+ initializer :add_view_paths, :after => :initialize_framework_views do
+ ActionController::Base.view_paths.concat ["#{path}/app/views"] if File.directory?("#{path}/app/views")
end
-
- def evaluate_init_rb(initializer)
- if has_init_file?
- require 'active_support/core_ext/kernel/reporting'
- silence_warnings do
- # Allow plugins to reference the current configuration object
- config = initializer.configuration
-
- eval(IO.read(init_path), binding, init_path)
- end
+ initializer :add_routing_file, :after => :initialize_routing do |app|
+ routing_file = "#{path}/config/routes.rb"
+ if File.exist?(routing_file)
+ app.routes.add_configuration_file(routing_file)
+ app.routes.reload!
end
- end
- end
-
- # This Plugin subclass represents a Gem plugin. Although RubyGems has already
- # taken care of $LOAD_PATHs, it exposes its load_paths to add them
- # to Dependencies.load_paths.
- class GemPlugin < Plugin
- # Initialize this plugin from a Gem::Specification.
- def initialize(spec, gem)
- directory = spec.full_gem_path
- super(directory)
- @name = spec.name
- end
-
- def init_path
- File.join(directory, 'rails', 'init.rb')
+ end
end
end
-end
+end \ No newline at end of file
diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb
deleted file mode 100644
index 0d16cbd7c3..0000000000
--- a/railties/lib/rails/plugin/loader.rb
+++ /dev/null
@@ -1,200 +0,0 @@
-require "rails/plugin"
-
-module Rails
- class Plugin
- class Loader
- attr_reader :initializer
-
- # Creates a new Plugin::Loader instance, associated with the given
- # Rails::Initializer. This default implementation automatically locates
- # all plugins, and adds all plugin load paths, when it is created. The plugins
- # are then fully loaded (init.rb is evaluated) when load_plugins is called.
- #
- # It is the loader's responsibility to ensure that only the plugins specified
- # in the configuration are actually loaded, and that the order defined
- # is respected.
- def initialize(initializer)
- @initializer = initializer
- end
-
- # Returns the plugins to be loaded, in the order they should be loaded.
- def plugins
- @plugins ||= all_plugins.select { |plugin| should_load?(plugin) }.sort { |p1, p2| order_plugins(p1, p2) }
- end
-
- # Returns the plugins that are in engine-form (have an app/ directory)
- def engines
- @engines ||= plugins.select {|plugin| plugin.engine? }
- end
-
- # Returns all the plugins that could be found by the current locators.
- def all_plugins
- @all_plugins ||= locate_plugins
- @all_plugins
- end
-
- def load_plugins
- plugins.each do |plugin|
- plugin.load(initializer)
- register_plugin_as_loaded(plugin)
- end
-
- configure_engines
-
- ensure_all_registered_plugins_are_loaded!
- end
-
- # Adds the load paths for every plugin into the $LOAD_PATH. Plugin load paths are
- # added *after* the application's <tt>lib</tt> directory, to ensure that an application
- # can always override code within a plugin.
- #
- # Plugin load paths are also added to Dependencies.load_paths, and Dependencies.load_once_paths.
- def add_plugin_load_paths
- plugins.each do |plugin|
- plugin.load_paths.each do |path|
- $LOAD_PATH.insert(application_lib_index + 1, path)
-
- ActiveSupport::Dependencies.load_paths << path
-
- unless configuration.reload_plugins?
- ActiveSupport::Dependencies.load_once_paths << path
- end
- end
- end
-
- $LOAD_PATH.uniq!
- end
-
- def engine_metal_paths
- engines.collect {|engine| engine.metal_path }
- end
-
- protected
- def configure_engines
- if engines.any?
- add_engine_routing_configurations
- add_engine_locales
- add_engine_controller_paths
- add_engine_view_paths
- end
- end
-
- def add_engine_routing_configurations
- engines.select {|engine| engine.routed? }.map {|engine| engine.routing_file }.each do |routing_file|
- ActionController::Routing::Routes.add_configuration_file(routing_file)
- end
- end
-
- def add_engine_locales
- localized_engines = engines.select { |engine| engine.localized? }
-
- # reverse it such that the last engine can overwrite translations from the first, like with routes
- locale_files = localized_engines.collect { |engine| engine.locale_files }.reverse.flatten
- I18n.load_path += locale_files - I18n.load_path
- end
-
- def add_engine_controller_paths
- ActionController::Routing.controller_paths += engines.collect {|engine| engine.controller_path }
- end
-
- def add_engine_view_paths
- # reverse it such that the last engine can overwrite view paths from the first, like with routes
- paths = ActionView::PathSet.new(engines.collect {|engine| engine.view_path }.reverse)
- ActionController::Base.view_paths.concat(paths)
- ActionMailer::Base.view_paths.concat(paths) if configuration.frameworks.include?(:action_mailer)
- end
-
- # The locate_plugins method uses each class in config.plugin_locators to
- # find the set of all plugins available to this Rails application.
- def locate_plugins
- configuration.plugin_locators.map do |locator|
- locator.new(initializer).plugins
- end.flatten
- # TODO: sorting based on config.plugins
- end
-
- def register_plugin_as_loaded(plugin)
- initializer.config.loaded_plugins << plugin
- end
-
- def configuration
- initializer.configuration
- end
-
- def should_load?(plugin)
- # uses Plugin#name and Plugin#valid?
- enabled?(plugin) && plugin.valid?
- end
-
- def order_plugins(plugin_a, plugin_b)
- if !explicit_plugin_loading_order?
- plugin_a <=> plugin_b
- else
- if !explicitly_enabled?(plugin_a) && !explicitly_enabled?(plugin_b)
- plugin_a <=> plugin_b
- else
- effective_order_of(plugin_a) <=> effective_order_of(plugin_b)
- end
- end
- end
-
- def effective_order_of(plugin)
- if explicitly_enabled?(plugin)
- registered_plugin_names.index(plugin.name)
- else
- registered_plugin_names.index('all')
- end
- end
-
- def application_lib_index
- $LOAD_PATH.index(File.join(RAILS_ROOT, 'lib')) || 0
- end
-
- def enabled?(plugin)
- !explicit_plugin_loading_order? || registered?(plugin)
- end
-
- def explicit_plugin_loading_order?
- !registered_plugin_names.nil?
- end
-
- def registered?(plugin)
- explicit_plugin_loading_order? && registered_plugins_names_plugin?(plugin)
- end
-
- def explicitly_enabled?(plugin)
- !explicit_plugin_loading_order? || explicitly_registered?(plugin)
- end
-
- def explicitly_registered?(plugin)
- explicit_plugin_loading_order? && registered_plugin_names.include?(plugin.name)
- end
-
- def registered_plugins_names_plugin?(plugin)
- registered_plugin_names.include?(plugin.name) || registered_plugin_names.include?('all')
- end
-
- # The plugins that have been explicitly listed with config.plugins. If this list is nil
- # then it means the client does not care which plugins or in what order they are loaded,
- # so we load all in alphabetical order. If it is an empty array, we load no plugins, if it is
- # non empty, we load the named plugins in the order specified.
- def registered_plugin_names
- configuration.plugins ? configuration.plugins.map {|plugin| plugin.to_s } : nil
- end
-
- def loaded?(plugin_name)
- initializer.config.loaded_plugins.detect { |plugin| plugin.name == plugin_name.to_s }
- end
-
- def ensure_all_registered_plugins_are_loaded!
- if explicit_plugin_loading_order?
- if configuration.plugins.detect {|plugin| plugin != :all && !loaded?(plugin) }
- missing_plugins = configuration.plugins - (plugins.map{|p| p.name.to_sym} + [:all])
- raise LoadError, "Could not locate the following plugins: #{missing_plugins.to_sentence(:locale => :en)}"
- end
- end
- end
-
- end
- end
-end
diff --git a/railties/lib/rails/plugin/locator.rb b/railties/lib/rails/plugin/locator.rb
deleted file mode 100644
index 1057c004e0..0000000000
--- a/railties/lib/rails/plugin/locator.rb
+++ /dev/null
@@ -1,100 +0,0 @@
-module Rails
- class Plugin
-
- # The Plugin::Locator class should be subclasses to provide custom plugin-finding
- # abilities to Rails (i.e. loading plugins from Gems, etc). Each subclass should implement
- # the <tt>located_plugins</tt> method, which return an array of Plugin objects that have been found.
- class Locator
- include Enumerable
-
- attr_reader :initializer
-
- def initialize(initializer)
- @initializer = initializer
- end
-
- # This method should return all the plugins which this Plugin::Locator can find
- # These will then be used by the current Plugin::Loader, which is responsible for actually
- # loading the plugins themselves
- def plugins
- raise "The `plugins' method must be defined by concrete subclasses of #{self.class}"
- end
-
- def each(&block)
- plugins.each(&block)
- end
-
- def plugin_names
- plugins.map {|plugin| plugin.name }
- end
- end
-
- # The Rails::Plugin::FileSystemLocator will try to locate plugins by examining the directories
- # in the paths given in configuration.plugin_paths. Any plugins that can be found are returned
- # in a list.
- #
- # The criteria for a valid plugin in this case is found in Rails::Plugin#valid?, although
- # other subclasses of Rails::Plugin::Locator can of course use different conditions.
- class FileSystemLocator < Locator
-
- # Returns all the plugins which can be loaded in the filesystem, under the paths given
- # by configuration.plugin_paths.
- def plugins
- initializer.configuration.plugin_paths.flatten.inject([]) do |plugins, path|
- plugins.concat locate_plugins_under(path)
- plugins
- end.flatten
- end
-
- private
-
- # Attempts to create a plugin from the given path. If the created plugin is valid?
- # (see Rails::Plugin#valid?) then the plugin instance is returned; otherwise nil.
- def create_plugin(path)
- plugin = Rails::Plugin.new(path)
- plugin.valid? ? plugin : nil
- end
-
- # This starts at the base path looking for valid plugins (see Rails::Plugin#valid?).
- # Since plugins can be nested arbitrarily deep within an unspecified number of intermediary
- # directories, this method runs recursively until it finds a plugin directory, e.g.
- #
- # locate_plugins_under('vendor/plugins/acts/acts_as_chunky_bacon')
- # => <Rails::Plugin name: 'acts_as_chunky_bacon' ... >
- #
- def locate_plugins_under(base_path)
- Dir.glob(File.join(base_path, '*')).sort.inject([]) do |plugins, path|
- if plugin = create_plugin(path)
- plugins << plugin
- elsif File.directory?(path)
- plugins.concat locate_plugins_under(path)
- end
- plugins
- end
- end
- end
-
- # The GemLocator scans all the loaded RubyGems, looking for gems with
- # a <tt>rails/init.rb</tt> file.
- class GemLocator < Locator
- def plugins
- gem_index = initializer.configuration.gems.inject({}) { |memo, gem| memo.update gem.specification => gem }
- specs = gem_index.keys
- specs += Gem.loaded_specs.values.select do |spec|
- spec.loaded_from && # prune stubs
- File.exist?(File.join(spec.full_gem_path, "rails", "init.rb"))
- end
- specs.compact!
-
- require "rubygems/dependency_list"
-
- deps = Gem::DependencyList.new
- deps.add(*specs) unless specs.empty?
-
- deps.dependency_order.collect do |spec|
- Rails::GemPlugin.new(spec, gem_index[spec])
- end
- end
- end
- end
-end \ No newline at end of file
diff --git a/railties/lib/rails/ruby_version_check.rb b/railties/lib/rails/ruby_version_check.rb
index 68d3acc876..62d7804bf3 100644
--- a/railties/lib/rails/ruby_version_check.rb
+++ b/railties/lib/rails/ruby_version_check.rb
@@ -1,13 +1,6 @@
-min_release = "1.8.2 (2004-12-25)"
+min_release = "1.8.7"
ruby_release = "#{RUBY_VERSION} (#{RUBY_RELEASE_DATE})"
-if ruby_release =~ /1\.8\.3/
- abort <<-end_message
-
- Rails does not work with Ruby version 1.8.3.
- Please upgrade to version 1.8.4 or downgrade to 1.8.2.
-
- end_message
-elsif ruby_release < min_release
+if ruby_release < min_release
abort <<-end_message
Rails requires Ruby version #{min_release} or later.
diff --git a/railties/lib/rails/tasks.rb b/railties/lib/rails/tasks.rb
index aad965306c..82113a297c 100644
--- a/railties/lib/rails/tasks.rb
+++ b/railties/lib/rails/tasks.rb
@@ -6,7 +6,6 @@ $VERBOSE = nil
databases
documentation
framework
- gems
log
middleware
misc
@@ -20,5 +19,5 @@ end
# Load any custom rakefile extensions
# TODO: Don't hardcode these paths.
-Dir["#{RAILS_ROOT}/vendor/plugins/*/**/tasks/**/*.rake"].sort.each { |ext| load ext }
-Dir["#{RAILS_ROOT}/lib/tasks/**/*.rake"].sort.each { |ext| load ext }
+Dir["#{Rails.root}/vendor/plugins/*/**/tasks/**/*.rake"].sort.each { |ext| load ext }
+Dir["#{Rails.root}/lib/tasks/**/*.rake"].sort.each { |ext| load ext }
diff --git a/railties/lib/rails/tasks/databases.rake b/railties/lib/rails/tasks/databases.rake
index ed015e7a67..a35a6c156b 100644
--- a/railties/lib/rails/tasks/databases.rake
+++ b/railties/lib/rails/tasks/databases.rake
@@ -283,7 +283,7 @@ namespace :db do
desc "Create a db/schema.rb file that can be portably used against any DB supported by AR"
task :dump => :environment do
require 'active_record/schema_dumper'
- File.open(ENV['SCHEMA'] || "#{RAILS_ROOT}/db/schema.rb", "w") do |file|
+ File.open(ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb", "w") do |file|
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
end
Rake::Task["db:schema:dump"].reenable
@@ -291,11 +291,11 @@ namespace :db do
desc "Load a schema.rb file into the database"
task :load => :environment do
- file = ENV['SCHEMA'] || "#{RAILS_ROOT}/db/schema.rb"
+ file = ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb"
if File.exists?(file)
load(file)
else
- abort %{#{file} doesn't exist yet. Run "rake db:migrate" to create it then try again. If you do not intend to use a database, you should instead alter #{RAILS_ROOT}/config/environment.rb to prevent active_record from loading: config.frameworks -= [ :active_record ]}
+ abort %{#{file} doesn't exist yet. Run "rake db:migrate" to create it then try again. If you do not intend to use a database, you should instead alter #{Rails.root}/config/application.rb to prevent active_record from loading: config.frameworks -= [ :active_record ]}
end
end
end
@@ -307,7 +307,7 @@ namespace :db do
case abcs[RAILS_ENV]["adapter"]
when "mysql", "oci", "oracle"
ActiveRecord::Base.establish_connection(abcs[RAILS_ENV])
- File.open("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
+ File.open("#{Rails.root}/db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
when "postgresql"
ENV['PGHOST'] = abcs[RAILS_ENV]["host"] if abcs[RAILS_ENV]["host"]
ENV['PGPORT'] = abcs[RAILS_ENV]["port"].to_s if abcs[RAILS_ENV]["port"]
@@ -327,13 +327,13 @@ namespace :db do
when "firebird"
set_firebird_env(abcs[RAILS_ENV])
db_string = firebird_db_string(abcs[RAILS_ENV])
- sh "isql -a #{db_string} > #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql"
+ sh "isql -a #{db_string} > #{Rails.root}/db/#{RAILS_ENV}_structure.sql"
else
raise "Task not supported by '#{abcs["test"]["adapter"]}'"
end
if ActiveRecord::Base.connection.supports_migrations?
- File.open("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information }
+ File.open("#{Rails.root}/db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information }
end
end
end
@@ -356,28 +356,28 @@ namespace :db do
when "mysql"
ActiveRecord::Base.establish_connection(:test)
ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0')
- IO.readlines("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table|
+ IO.readlines("#{Rails.root}/db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table|
ActiveRecord::Base.connection.execute(table)
end
when "postgresql"
ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"]
ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"]
ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"]
- `psql -U "#{abcs["test"]["username"]}" -f #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql #{abcs["test"]["database"]}`
+ `psql -U "#{abcs["test"]["username"]}" -f #{Rails.root}/db/#{RAILS_ENV}_structure.sql #{abcs["test"]["database"]}`
when "sqlite", "sqlite3"
dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"]
- `#{abcs["test"]["adapter"]} #{dbfile} < #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql`
+ `#{abcs["test"]["adapter"]} #{dbfile} < #{Rails.root}/db/#{RAILS_ENV}_structure.sql`
when "sqlserver"
`osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql`
when "oci", "oracle"
ActiveRecord::Base.establish_connection(:test)
- IO.readlines("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl|
+ IO.readlines("#{Rails.root}/db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl|
ActiveRecord::Base.connection.execute(ddl)
end
when "firebird"
set_firebird_env(abcs["test"])
db_string = firebird_db_string(abcs["test"])
- sh "isql -i #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql #{db_string}"
+ sh "isql -i #{Rails.root}/db/#{RAILS_ENV}_structure.sql #{db_string}"
else
raise "Task not supported by '#{abcs["test"]["adapter"]}'"
end
@@ -446,7 +446,7 @@ def drop_database(config)
when /^sqlite/
require 'pathname'
path = Pathname.new(config['database'])
- file = path.absolute? ? path.to_s : File.join(RAILS_ROOT, path)
+ file = path.absolute? ? path.to_s : File.join(Rails.root, path)
FileUtils.rm(file)
when 'postgresql'
diff --git a/railties/lib/rails/tasks/framework.rake b/railties/lib/rails/tasks/framework.rake
index 16dd0af44e..1611d1d94d 100644
--- a/railties/lib/rails/tasks/framework.rake
+++ b/railties/lib/rails/tasks/framework.rake
@@ -86,7 +86,7 @@ namespace :rails do
template = File.expand_path(template) if template !~ %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://}
require 'generators'
- generator = Rails::Generators::App.new [ RAILS_ROOT ], {}, :destination_root => RAILS_ROOT
+ generator = Rails::Generators::App.new [ Rails.root ], {}, :destination_root => Rails.root
generator.apply template, :verbose => false
end
@@ -96,15 +96,10 @@ namespace :rails do
require 'rails/generators/rails/app/app_generator'
generator = Rails::Generators::AppGenerator.new ["rails"], { :with_dispatchers => true },
- :destination_root => RAILS_ROOT
+ :destination_root => Rails.root
generator.invoke(method)
end
- desc "Update config/boot.rb from your current rails install"
- task :configs do
- invoke_from_app_generator :create_boot_file
- end
-
desc "Update Prototype javascripts from your current rails install"
task :javascripts do
invoke_from_app_generator :create_prototype_files
@@ -117,8 +112,8 @@ namespace :rails do
desc "Rename application.rb to application_controller.rb"
task :application_controller do
- old_style = RAILS_ROOT + '/app/controllers/application.rb'
- new_style = RAILS_ROOT + '/app/controllers/application_controller.rb'
+ old_style = Rails.root + '/app/controllers/application.rb'
+ new_style = Rails.root + '/app/controllers/application_controller.rb'
if File.exists?(old_style) && !File.exists?(new_style)
FileUtils.mv(old_style, new_style)
puts "#{old_style} has been renamed to #{new_style}, update your SCM as necessary"
diff --git a/railties/lib/rails/tasks/gems.rake b/railties/lib/rails/tasks/gems.rake
deleted file mode 100644
index f1c34c7cca..0000000000
--- a/railties/lib/rails/tasks/gems.rake
+++ /dev/null
@@ -1,78 +0,0 @@
-desc "List the gems that this rails application depends on"
-task :gems => 'gems:base' do
- Rails.configuration.gems.each do |gem|
- print_gem_status(gem)
- end
- puts
- puts "I = Installed"
- puts "F = Frozen"
- puts "R = Framework (loaded before rails starts)"
-end
-
-namespace :gems do
- task :base do
- $gems_rake_task = true
- require 'rubygems'
- require 'rubygems/gem_runner'
- Rake::Task[:environment].invoke
- end
-
- desc "Build any native extensions for unpacked gems"
- task :build do
- $gems_build_rake_task = true
- frozen_gems.each { |gem| gem.build }
- end
-
- namespace :build do
- desc "Force the build of all gems"
- task :force do
- $gems_build_rake_task = true
- frozen_gems.each { |gem| gem.build(:force => true) }
- end
- end
-
- desc "Installs all required gems."
- task :install => :base do
- current_gems.each { |gem| gem.install }
- end
-
- desc "Unpacks all required gems into vendor/gems."
- task :unpack => :install do
- current_gems.each { |gem| gem.unpack }
- end
-
- namespace :unpack do
- desc "Unpacks all required gems and their dependencies into vendor/gems."
- task :dependencies => :install do
- current_gems.each { |gem| gem.unpack(:recursive => true) }
- end
- end
-
- desc "Regenerate gem specifications in correct format."
- task :refresh_specs do
- frozen_gems(false).each { |gem| gem.refresh }
- end
-end
-
-def current_gems
- gems = Rails.configuration.gems
- gems = gems.select { |gem| gem.name == ENV['GEM'] } unless ENV['GEM'].blank?
- gems
-end
-
-def frozen_gems(load_specs=true)
- Dir[File.join(RAILS_ROOT, 'vendor', 'gems', '*-*')].map do |gem_dir|
- Rails::GemDependency.from_directory_name(gem_dir, load_specs)
- end
-end
-
-def print_gem_status(gem, indent=1)
- code = case
- when gem.framework_gem? then 'R'
- when gem.frozen? then 'F'
- when gem.installed? then 'I'
- else ' '
- end
- puts " "*(indent-1)+" - [#{code}] #{gem.name} #{gem.requirement.to_s}"
- gem.dependencies.each { |g| print_gem_status(g, indent+1) }
-end
diff --git a/railties/lib/rails/tasks/misc.rake b/railties/lib/rails/tasks/misc.rake
index fb2fc31dc1..7f244ebaed 100644
--- a/railties/lib/rails/tasks/misc.rake
+++ b/railties/lib/rails/tasks/misc.rake
@@ -1,7 +1,7 @@
task :default => :test
task :environment do
$rails_rake_task = true
- require(File.join(RAILS_ROOT, 'config', 'environment'))
+ require(File.join(Rails.root, 'config', 'environment'))
end
task :rails_env do
diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake
index abbf3258c1..2395d73b2f 100644
--- a/railties/lib/rails/tasks/routes.rake
+++ b/railties/lib/rails/tasks/routes.rake
@@ -3,16 +3,13 @@ task :routes => :environment do
all_routes = ENV['CONTROLLER'] ? ActionController::Routing::Routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : ActionController::Routing::Routes.routes
routes = all_routes.collect do |route|
name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s
- verb = route.conditions[:method].to_s.upcase
- segs = route.segments.inject("") { |str,s| str << s.to_s }
- segs.chop! if segs.length > 1
reqs = route.requirements.empty? ? "" : route.requirements.inspect
- {:name => name, :verb => verb, :segs => segs, :reqs => reqs}
+ {:name => name, :verb => route.verb.to_s, :path => route.path, :reqs => reqs}
end
name_width = routes.collect {|r| r[:name]}.collect {|n| n.length}.max
verb_width = routes.collect {|r| r[:verb]}.collect {|v| v.length}.max
- segs_width = routes.collect {|r| r[:segs]}.collect {|s| s.length}.max
+ path_width = routes.collect {|r| r[:path]}.collect {|s| s.length}.max
routes.each do |r|
- puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:segs].ljust(segs_width)} #{r[:reqs]}"
+ puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}"
end
end
diff --git a/railties/lib/rails/tasks/statistics.rake b/railties/lib/rails/tasks/statistics.rake
index 2dcc7bdf9d..40f8c1034a 100644
--- a/railties/lib/rails/tasks/statistics.rake
+++ b/railties/lib/rails/tasks/statistics.rake
@@ -1,14 +1,13 @@
STATS_DIRECTORIES = [
%w(Controllers app/controllers),
- %w(Helpers app/helpers),
+ %w(Helpers app/helpers),
%w(Models app/models),
%w(Libraries lib/),
%w(APIs app/apis),
%w(Integration\ tests test/integration),
%w(Functional\ tests test/functional),
%w(Unit\ tests test/unit)
-
-].collect { |name, dir| [ name, "#{RAILS_ROOT}/#{dir}" ] }.select { |name, dir| File.directory?(dir) }
+].collect { |name, dir| [ name, "#{Rails.root}/#{dir}" ] }.select { |name, dir| File.directory?(dir) }
desc "Report code statistics (KLOCs, etc) from the application"
task :stats do
diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb
index 8bd4475c7b..9f6c42945f 100644
--- a/railties/lib/rails/test_help.rb
+++ b/railties/lib/rails/test_help.rb
@@ -17,7 +17,7 @@ if defined?(ActiveRecord)
class ActiveSupport::TestCase
include ActiveRecord::TestFixtures
- self.fixture_path = "#{RAILS_ROOT}/test/fixtures/"
+ self.fixture_path = "#{Rails.root}/test/fixtures/"
self.use_instantiated_fixtures = false
self.use_transactional_fixtures = true
end
diff --git a/railties/lib/rails/vendor/thor-0.11.6/bin/rake2thor b/railties/lib/rails/vendor/thor-0.11.6/bin/rake2thor
deleted file mode 100755
index 50c7410d80..0000000000
--- a/railties/lib/rails/vendor/thor-0.11.6/bin/rake2thor
+++ /dev/null
@@ -1,87 +0,0 @@
-#!/usr/bin/env ruby
-
-require 'rubygems'
-require 'ruby2ruby'
-require 'parse_tree'
-if Ruby2Ruby::VERSION >= "1.2.0"
- require 'parse_tree_extensions'
-end
-require 'rake'
-
-input = ARGV[0] || 'Rakefile'
-output = ARGV[1] || 'Thorfile'
-
-$requires = []
-
-module Kernel
- def require_with_record(file)
- $requires << file if caller[1] =~ /rake2thor:/
- require_without_record file
- end
- alias_method :require_without_record, :require
- alias_method :require, :require_with_record
-end
-
-load input
-
-@private_methods = []
-
-def file_task_name(name)
- "compile_" + name.gsub('/', '_slash_').gsub('.', '_dot_').gsub(/\W/, '_')
-end
-
-def method_for_task(task)
- file_task = task.is_a?(Rake::FileTask)
- comment = task.instance_variable_get('@comment')
- prereqs = task.instance_variable_get('@prerequisites').select(&Rake::Task.method(:task_defined?))
- actions = task.instance_variable_get('@actions')
- name = task.name.gsub(/^([^:]+:)+/, '')
- name = file_task_name(name) if file_task
- meth = ''
-
- meth << "desc #{name.inspect}, #{comment.inspect}\n" if comment
- meth << "def #{name}\n"
-
- meth << prereqs.map do |pre|
- pre = pre.to_s
- pre = file_task_name(pre) if Rake::Task[pre].is_a?(Rake::FileTask)
- ' ' + pre
- end.join("\n")
-
- meth << "\n\n" unless prereqs.empty? || actions.empty?
-
- meth << actions.map do |act|
- act = act.to_ruby
- unless act.gsub!(/^proc \{ \|(\w+)\|\n/,
- " \\1 = Struct.new(:name).new(#{name.inspect}) # A crude mock Rake::Task object\n")
- act.gsub!(/^proc \{\n/, '')
- end
- act.gsub(/\n\}$/, '')
- end.join("\n")
-
- meth << "\nend"
-
- if file_task
- @private_methods << meth
- return
- end
-
- meth
-end
-
-body = Rake::Task.tasks.map(&method(:method_for_task)).compact.map { |meth| meth.gsub(/^/, ' ') }.join("\n\n")
-
-unless @private_methods.empty?
- body << "\n\n private\n\n"
- body << @private_methods.map { |meth| meth.gsub(/^/, ' ') }.join("\n\n")
-end
-
-requires = $requires.map { |r| "require #{r.inspect}" }.join("\n")
-
-File.open(output, 'w') { |f| f.write(<<END.lstrip) }
-#{requires}
-
-class Default < Thor
-#{body}
-end
-END
diff --git a/railties/lib/rails/vendor/thor-0.11.6/bin/thor b/railties/lib/rails/vendor/thor-0.11.6/bin/thor
deleted file mode 100755
index eaf849fb4a..0000000000
--- a/railties/lib/rails/vendor/thor-0.11.6/bin/thor
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/usr/bin/env ruby
-# -*- mode: ruby -*-
-
-require File.join(File.dirname(__FILE__), '..', 'lib', 'thor')
-require 'thor/runner'
-
-Thor::Runner.start
diff --git a/railties/lib/rails/vendor/thor-0.11.6/CHANGELOG.rdoc b/railties/lib/rails/vendor/thor-0.12.0/CHANGELOG.rdoc
index dba25b7205..adedfeca9d 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/CHANGELOG.rdoc
+++ b/railties/lib/rails/vendor/thor-0.12.0/CHANGELOG.rdoc
@@ -2,7 +2,12 @@
* Improve spec coverage for Thor::Runner
-== 0.11.x, released 2009-07-01
+== 0.12, released 2009-11-06
+
+* [#7] Do not force white color on status
+* [#8] Yield a block with the filename on directory
+
+== 0.11, released 2009-07-01
* Added a rake compatibility layer. It allows you to use spec and rdoc tasks on
Thor classes.
diff --git a/railties/lib/rails/vendor/thor-0.11.6/LICENSE b/railties/lib/rails/vendor/thor-0.12.0/LICENSE
index 98722da459..98722da459 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/LICENSE
+++ b/railties/lib/rails/vendor/thor-0.12.0/LICENSE
diff --git a/railties/lib/rails/vendor/thor-0.11.6/README.rdoc b/railties/lib/rails/vendor/thor-0.12.0/README.rdoc
index f1106f02b6..f1106f02b6 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/README.rdoc
+++ b/railties/lib/rails/vendor/thor-0.12.0/README.rdoc
diff --git a/railties/lib/rails/vendor/thor-0.12.0/Thorfile b/railties/lib/rails/vendor/thor-0.12.0/Thorfile
new file mode 100644
index 0000000000..f71a1e57e2
--- /dev/null
+++ b/railties/lib/rails/vendor/thor-0.12.0/Thorfile
@@ -0,0 +1,63 @@
+# enconding: utf-8
+
+require File.join(File.dirname(__FILE__), "lib", "thor", "version")
+require 'thor/rake_compat'
+require 'spec/rake/spectask'
+require 'rdoc/task'
+
+GEM_NAME = 'thor'
+EXTRA_RDOC_FILES = ["README.rdoc", "LICENSE", "CHANGELOG.rdoc", "VERSION", "Thorfile"]
+
+class Default < Thor
+ include Thor::RakeCompat
+
+ Spec::Rake::SpecTask.new(:spec) do |t|
+ t.libs << 'lib'
+ t.spec_opts = ['--options', "spec/spec.opts"]
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ end
+
+ Spec::Rake::SpecTask.new(:rcov) do |t|
+ t.libs << 'lib'
+ t.spec_opts = ['--options', "spec/spec.opts"]
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ t.rcov = true
+ t.rcov_dir = "rcov"
+ end
+
+ RDoc::Task.new do |rdoc|
+ rdoc.main = "README.rdoc"
+ rdoc.rdoc_dir = "rdoc"
+ rdoc.title = GEM_NAME
+ rdoc.rdoc_files.include(*EXTRA_RDOC_FILES)
+ rdoc.rdoc_files.include('lib/**/*.rb')
+ rdoc.options << '--line-numbers' << '--inline-source'
+ end
+
+ begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |s|
+ s.name = GEM_NAME
+ s.version = Thor::VERSION
+ s.rubyforge_project = "textmate"
+ s.platform = Gem::Platform::RUBY
+ s.summary = "A scripting framework that replaces rake, sake and rubigen"
+ s.email = "ruby-thor@googlegroups.com"
+ s.homepage = "http://yehudakatz.com"
+ s.description = "A scripting framework that replaces rake, sake and rubigen"
+ s.authors = ['Yehuda Katz', 'José Valim']
+ s.has_rdoc = true
+ s.extra_rdoc_files = EXTRA_RDOC_FILES
+ s.require_path = 'lib'
+ s.bindir = "bin"
+ s.executables = %w( thor rake2thor )
+ s.files = s.extra_rdoc_files + Dir.glob("{bin,lib}/**/*")
+ s.files.exclude 'spec/sandbox/**/*'
+ s.test_files.exclude 'spec/sandbox/**/*'
+ end
+
+ Jeweler::RubyforgeTasks.new
+ rescue LoadError
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
+ end
+end
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor.rb
index 3b45c4e9b7..68944f140d 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor.rb
@@ -1,4 +1,3 @@
-$:.unshift File.expand_path(File.dirname(__FILE__))
require 'thor/base'
require 'thor/group'
require 'thor/actions'
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions.rb
index d561ccb2aa..d561ccb2aa 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/create_file.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/create_file.rb
index 8f6badee27..a3d9296823 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/create_file.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/create_file.rb
@@ -60,6 +60,7 @@ class Thor
FileUtils.mkdir_p(File.dirname(destination))
File.open(destination, 'w'){ |f| f.write render }
end
+ given_destination
end
protected
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/directory.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/directory.rb
index be5eb822ac..467e63732a 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/directory.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/directory.rb
@@ -40,15 +40,16 @@ class Thor
# directory "doc"
# directory "doc", "docs", :recursive => false
#
- def directory(source, destination=nil, config={})
- action Directory.new(self, source, destination || source, config)
+ def directory(source, destination=nil, config={}, &block)
+ action Directory.new(self, source, destination || source, config, &block)
end
class Directory < EmptyDirectory #:nodoc:
attr_reader :source
- def initialize(base, source, destination=nil, config={})
+ def initialize(base, source, destination=nil, config={}, &block)
@source = File.expand_path(base.find_in_source_paths(source.to_s))
+ @block = block
super(base, destination, { :recursive => true }.merge(config))
end
@@ -70,14 +71,19 @@ class Thor
Dir[lookup].each do |file_source|
next if File.directory?(file_source)
file_destination = File.join(given_destination, file_source.gsub(source, '.'))
+ file_destination.gsub!('/./', '/')
case file_source
when /\.empty_directory$/
- base.empty_directory(File.dirname(file_destination), config)
+ dirname = File.dirname(file_destination).gsub(/\/\.$/, '')
+ next if dirname == given_destination
+ base.empty_directory(dirname, config)
when /\.tt$/
- base.template(file_source, file_destination[0..-4], config)
+ destination = base.template(file_source, file_destination[0..-4], config)
+ @block.call(destination) if @block
else
- base.copy_file(file_source, file_destination, config)
+ destination = base.copy_file(file_source, file_destination, config)
+ @block.call(destination) if @block
end
end
end
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/empty_directory.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/empty_directory.rb
index 03c1fe4af1..484cb820f8 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/empty_directory.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/empty_directory.rb
@@ -55,6 +55,7 @@ class Thor
def revoke!
say_status :remove, :red
::FileUtils.rm_rf(destination) if !pretend? && exists?
+ given_destination
end
protected
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/file_manipulation.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/file_manipulation.rb
index d77d90d448..d77d90d448 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/file_manipulation.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/file_manipulation.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/inject_into_file.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/inject_into_file.rb
index 0636ec6591..0636ec6591 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/actions/inject_into_file.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/actions/inject_into_file.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/base.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/base.rb
index 700d794123..700d794123 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/base.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/base.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/core_ext/hash_with_indifferent_access.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/core_ext/hash_with_indifferent_access.rb
index 78bc5cf4bf..78bc5cf4bf 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/core_ext/hash_with_indifferent_access.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/core_ext/hash_with_indifferent_access.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/core_ext/ordered_hash.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/core_ext/ordered_hash.rb
index 27fea5bb35..27fea5bb35 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/core_ext/ordered_hash.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/core_ext/ordered_hash.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/error.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/error.rb
index f9b31a35d1..f9b31a35d1 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/error.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/error.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/group.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/group.rb
index 1e59df2313..0964a9667a 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/group.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/group.rb
@@ -74,7 +74,7 @@ class Thor::Group
#
def invoke(*names, &block)
options = names.last.is_a?(Hash) ? names.pop : {}
- verbose = options.fetch(:verbose, :white)
+ verbose = options.fetch(:verbose, true)
names.each do |name|
invocations[name] = false
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/invocation.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/invocation.rb
index 32e6a72454..32e6a72454 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/invocation.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/invocation.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser.rb
index 57a3f6e1a5..57a3f6e1a5 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser/argument.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser/argument.rb
index aa8ace4719..aa8ace4719 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser/argument.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser/argument.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser/arguments.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser/arguments.rb
index fb5d965e06..fb5d965e06 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser/arguments.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser/arguments.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser/option.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser/option.rb
index 9e40ec73fa..9e40ec73fa 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser/option.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser/option.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser/options.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser/options.rb
index 75092308b5..75092308b5 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/parser/options.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/parser/options.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/rake_compat.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/rake_compat.rb
index 3ab6bb21f5..0d0757fdda 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/rake_compat.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/rake_compat.rb
@@ -22,7 +22,8 @@ class Thor
def self.included(base)
# Hack. Make rakefile point to invoker, so rdoc task is generated properly.
- Rake.application.instance_variable_set(:@rakefile, caller[0].match(/(.*):\d+/)[1])
+ rakefile = File.basename(caller[0].match(/(.*):\d+/)[1])
+ Rake.application.instance_variable_set(:@rakefile, rakefile)
self.rake_classes << base
end
end
@@ -43,11 +44,9 @@ class Object #:nodoc:
description.strip!
klass.desc description, task.comment || non_namespaced_name
- klass.class_eval <<-METHOD
- def #{non_namespaced_name}(#{task.arg_names.join(', ')})
- Rake::Task[#{task.name.to_sym.inspect}].invoke(#{task.arg_names.join(', ')})
- end
- METHOD
+ klass.send :define_method, non_namespaced_name do |*args|
+ Rake::Task[task.name.to_sym].invoke(*args)
+ end
end
task
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/runner.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/runner.rb
index 43da09b336..9dc70ea069 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/runner.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/runner.rb
@@ -215,7 +215,7 @@ class Thor::Runner < Thor #:nodoc:
# 5. c:\ <-- no Thorfiles found!
#
def thorfiles(relevant_to=nil, skip_lookup=false)
- # Deal with deprecated thor when :namespaces: is available as constants
+ # TODO Remove this dealing with deprecated thor when :namespaces: is available as constants
save_yaml(thor_yaml) if Thor::Util.convert_constants_to_namespaces(thor_yaml)
thorfiles = []
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/shell.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/shell.rb
index 0d3f4d5951..1dc8f0e5b4 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/shell.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/shell.rb
@@ -1,11 +1,17 @@
+require 'rbconfig'
require 'thor/shell/color'
class Thor
module Base
- # Returns the shell used in all Thor classes. Default to color one.
+ # Returns the shell used in all Thor classes. If you are in a Unix platform
+ # it will use a colored log, otherwise it will use a basic one without color.
#
def self.shell
- @shell ||= Thor::Shell::Color
+ @shell ||= if Config::CONFIG['host_os'] =~ /mswin|mingw/
+ Thor::Shell::Basic
+ else
+ Thor::Shell::Color
+ end
end
# Sets the shell used in all Thor classes.
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/shell/basic.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/shell/basic.rb
index ea9665380b..ea9665380b 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/shell/basic.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/shell/basic.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/shell/color.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/shell/color.rb
index 24704f7885..24704f7885 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/shell/color.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/shell/color.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/task.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/task.rb
index 91c7564d3f..91c7564d3f 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/task.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/task.rb
diff --git a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/util.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/util.rb
index fd820d7462..ebae0a3193 100644
--- a/railties/lib/rails/vendor/thor-0.11.6/lib/thor/util.rb
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/util.rb
@@ -209,7 +209,7 @@ class Thor
# Returns the root where thor files are located, dependending on the OS.
#
def self.thor_root
- File.join(user_home, ".thor")
+ File.join(user_home, ".thor").gsub(/\\/, '/')
end
# Returns the files in the thor root. On Windows thor_root will be something
@@ -220,7 +220,7 @@ class Thor
# If we don't #gsub the \ character, Dir.glob will fail.
#
def self.thor_root_glob
- files = Dir["#{thor_root.gsub(/\\/, '/')}/*"]
+ files = Dir["#{thor_root}/*"]
files.map! do |file|
File.directory?(file) ? File.join(file, "main.thor") : file
diff --git a/railties/lib/rails/vendor/thor-0.12.0/lib/thor/version.rb b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/version.rb
new file mode 100644
index 0000000000..885230fac4
--- /dev/null
+++ b/railties/lib/rails/vendor/thor-0.12.0/lib/thor/version.rb
@@ -0,0 +1,3 @@
+class Thor
+ VERSION = "0.11.8".freeze
+end
diff --git a/railties/lib/rails/vendor_gem_source_index.rb b/railties/lib/rails/vendor_gem_source_index.rb
deleted file mode 100644
index 5b7721f303..0000000000
--- a/railties/lib/rails/vendor_gem_source_index.rb
+++ /dev/null
@@ -1,140 +0,0 @@
-require 'rubygems'
-require 'yaml'
-
-module Rails
-
- class VendorGemSourceIndex
- # VendorGemSourceIndex acts as a proxy for the Gem source index, allowing
- # gems to be loaded from vendor/gems. Rather than the standard gem repository format,
- # vendor/gems contains unpacked gems, with YAML specifications in .specification in
- # each gem directory.
- include Enumerable
-
- attr_reader :installed_source_index
- attr_reader :vendor_source_index
-
- @@silence_spec_warnings = false
-
- def self.silence_spec_warnings
- @@silence_spec_warnings
- end
-
- def self.silence_spec_warnings=(v)
- @@silence_spec_warnings = v
- end
-
- def initialize(installed_index, vendor_dir=Rails::GemDependency.unpacked_path)
- @installed_source_index = installed_index
- @vendor_dir = vendor_dir
- refresh!
- end
-
- def refresh!
- # reload the installed gems
- @installed_source_index.refresh!
- vendor_gems = {}
-
- # handle vendor Rails gems - they are identified by having loaded_from set to ""
- # we add them manually to the list, so that other gems can find them via dependencies
- Gem.loaded_specs.each do |n, s|
- next unless s.loaded_from.empty?
- vendor_gems[s.full_name] = s
- end
-
- # load specifications from vendor/gems
- Dir[File.join(Rails::GemDependency.unpacked_path, '*')].each do |d|
- dir_name = File.basename(d)
- dir_version = version_for_dir(dir_name)
- spec = load_specification(d)
- if spec
- if spec.full_name != dir_name
- # mismatched directory name and gem spec - produced by 2.1.0-era unpack code
- if dir_version
- # fix the spec version - this is not optimal (spec.files may be wrong)
- # but it's better than breaking apps. Complain to remind users to get correct specs.
- # use ActiveSupport::Deprecation.warn, as the logger is not set yet
- $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems has a mismatched specification file."+
- " Run 'rake gems:refresh_specs' to fix this.") unless @@silence_spec_warnings
- spec.version = dir_version
- else
- $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems is not in a versioned directory"+
- "(should be #{spec.full_name}).") unless @@silence_spec_warnings
- # continue, assume everything is OK
- end
- end
- else
- # no spec - produced by early-2008 unpack code
- # emulate old behavior, and complain.
- $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems has no specification file."+
- " Run 'rake gems:refresh_specs' to fix this.") unless @@silence_spec_warnings
- if dir_version
- spec = Gem::Specification.new
- spec.version = dir_version
- spec.require_paths = ['lib']
- ext_path = File.join(d, 'ext')
- spec.require_paths << 'ext' if File.exist?(ext_path)
- spec.name = /^(.*)-[^-]+$/.match(dir_name)[1]
- files = ['lib']
- # set files to everything in lib/
- files += Dir[File.join(d, 'lib', '*')].map { |v| v.gsub(/^#{d}\//, '') }
- files += Dir[File.join(d, 'ext', '*')].map { |v| v.gsub(/^#{d}\//, '') } if ext_path
- spec.files = files
- else
- $stderr.puts("config.gem: Unpacked gem #{dir_name} in vendor/gems not in a versioned directory."+
- " Giving up.") unless @@silence_spec_warnings
- next
- end
- end
- spec.loaded_from = File.join(d, '.specification')
- # finally, swap out full_gem_path
- # it would be better to use a Gem::Specification subclass, but the YAML loads an explicit class
- class << spec
- def full_gem_path
- path = File.join installation_path, full_name
- return path if File.directory? path
- File.join installation_path, original_name
- end
- end
- vendor_gems[File.basename(d)] = spec
- end
- @vendor_source_index = Gem::SourceIndex.new(vendor_gems)
- end
-
- def version_for_dir(d)
- matches = /-([^-]+)$/.match(d)
- Gem::Version.new(matches[1]) if matches
- end
-
- def load_specification(gem_dir)
- spec_file = File.join(gem_dir, '.specification')
- YAML.load_file(spec_file) if File.exist?(spec_file)
- end
-
- def find_name(*args)
- @installed_source_index.find_name(*args) + @vendor_source_index.find_name(*args)
- end
-
- def search(*args)
- # look for vendor gems, and then installed gems - later elements take priority
- @installed_source_index.search(*args) + @vendor_source_index.search(*args)
- end
-
- def each(&block)
- @vendor_source_index.each(&block)
- @installed_source_index.each(&block)
- end
-
- def add_spec(spec)
- @vendor_source_index.add_spec spec
- end
-
- def remove_spec(spec)
- @vendor_source_index.remove_spec spec
- end
-
- def size
- @vendor_source_index.size + @installed_source_index.size
- end
-
- end
-end