aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG2
-rw-r--r--railties/Rakefile10
-rw-r--r--railties/environments/environment.rb5
-rw-r--r--railties/lib/commands/dbconsole.rb14
-rw-r--r--railties/lib/commands/plugin.rb2
-rw-r--r--railties/lib/initializer.rb44
-rw-r--r--railties/lib/rails/gem_dependency.rb15
-rw-r--r--railties/lib/rails/plugin.rb17
-rw-r--r--railties/lib/rails/rack.rb5
-rw-r--r--railties/lib/rails/rack/static.rb35
-rw-r--r--railties/lib/rails/version.rb4
-rw-r--r--railties/lib/rails_generator/commands.rb8
-rw-r--r--railties/lib/tasks/gems.rake12
13 files changed, 124 insertions, 49 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index 11d2926f31..fe517755ef 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,4 +1,4 @@
-*2.1.0 RC1 (May 11th, 2008)*
+*2.1.0 (May 31st, 2008)*
* script/dbconsole fires up the command-line database client. #102 [Steve Purcell]
diff --git a/railties/Rakefile b/railties/Rakefile
index 45ba394299..a1d1095c37 100644
--- a/railties/Rakefile
+++ b/railties/Rakefile
@@ -304,11 +304,11 @@ spec = Gem::Specification.new do |s|
EOF
s.add_dependency('rake', '>= 0.8.1')
- s.add_dependency('activesupport', '= 2.0.991' + PKG_BUILD)
- s.add_dependency('activerecord', '= 2.0.991' + PKG_BUILD)
- s.add_dependency('actionpack', '= 2.0.991' + PKG_BUILD)
- s.add_dependency('actionmailer', '= 2.0.991' + PKG_BUILD)
- s.add_dependency('activeresource', '= 2.0.991' + PKG_BUILD)
+ s.add_dependency('activesupport', '= 2.1.0' + PKG_BUILD)
+ s.add_dependency('activerecord', '= 2.1.0' + PKG_BUILD)
+ s.add_dependency('actionpack', '= 2.1.0' + PKG_BUILD)
+ s.add_dependency('actionmailer', '= 2.1.0' + PKG_BUILD)
+ s.add_dependency('activeresource', '= 2.1.0' + PKG_BUILD)
s.rdoc_options << '--exclude' << '.'
s.has_rdoc = false
diff --git a/railties/environments/environment.rb b/railties/environments/environment.rb
index 468fa45ef6..a85ade371b 100644
--- a/railties/environments/environment.rb
+++ b/railties/environments/environment.rb
@@ -64,7 +64,4 @@ Rails::Initializer.run do |config|
# Activate observers that should always be running
# config.active_record.observers = :cacher, :garbage_collector
-
- # Make ActiveRecord only save the attributes that have changed since the record was loaded.
- # config.active_record.partial_updates = true
-end \ No newline at end of file
+end
diff --git a/railties/lib/commands/dbconsole.rb b/railties/lib/commands/dbconsole.rb
index b81997aa59..17acb7b68f 100644
--- a/railties/lib/commands/dbconsole.rb
+++ b/railties/lib/commands/dbconsole.rb
@@ -2,8 +2,13 @@ require 'erb'
require 'yaml'
require 'optparse'
+include_password = false
+
OptionParser.new do |opt|
- opt.banner = "Usage: dbconsole [environment]"
+ opt.banner = "Usage: dbconsole [options] [environment]"
+ opt.on("-p", "--include-password", "Automatically provide the database from database.yml") do |v|
+ include_password = true
+ end
opt.parse!(ARGV)
abort opt.to_s unless (0..1).include?(ARGV.size)
end
@@ -31,10 +36,13 @@ when "mysql"
'port' => '--port',
'socket' => '--socket',
'username' => '--user',
- 'password' => '--password',
'encoding' => '--default-character-set'
}.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact
+ if config['password'] && include_password
+ args << "--password=#{config['password']}"
+ end
+
args << config['database']
exec(find_cmd('mysql5', 'mysql'), *args)
@@ -43,7 +51,7 @@ when "postgresql"
ENV['PGUSER'] = config["username"] if config["username"]
ENV['PGHOST'] = config["host"] if config["host"]
ENV['PGPORT'] = config["port"].to_s if config["port"]
- ENV['PGPASSWORD'] = config["password"].to_s if config["password"]
+ ENV['PGPASSWORD'] = config["password"].to_s if config["password"] && include_password
exec(find_cmd('psql'), config["database"])
when "sqlite"
diff --git a/railties/lib/commands/plugin.rb b/railties/lib/commands/plugin.rb
index d12d002c4e..105819ce90 100644
--- a/railties/lib/commands/plugin.rb
+++ b/railties/lib/commands/plugin.rb
@@ -163,7 +163,7 @@ class Plugin
end
def git_url?
- @uri =~ /^git:\/\// || @url =~ /\.git$/
+ @uri =~ /^git:\/\// || @uri =~ /\.git$/
end
def installed?
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb
index 8f963cb4a5..bdadfeea8f 100644
--- a/railties/lib/initializer.rb
+++ b/railties/lib/initializer.rb
@@ -8,6 +8,7 @@ require 'rails/version'
require 'rails/plugin/locator'
require 'rails/plugin/loader'
require 'rails/gem_dependency'
+require 'rails/rack'
RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
@@ -140,7 +141,8 @@ module Rails
# pick up any gems that plugins depend on
add_gem_load_paths
load_gems
-
+ check_gem_dependencies
+
load_application_initializers
# the framework is now fully initialized
@@ -153,6 +155,7 @@ module Rails
initialize_routing
# Observers are loaded after plugins in case Observers or observed models are modified by plugins.
+
load_observers
end
@@ -241,7 +244,24 @@ module Rails
end
def load_gems
- @configuration.gems.each &:load
+ @configuration.gems.each(&:load)
+ end
+
+ def check_gem_dependencies
+ unloaded_gems = @configuration.gems.reject { |g| g.loaded? }
+ if unloaded_gems.size > 0
+ @gems_dependencies_loaded = false
+ # don't print if the gems rake tasks are being run
+ unless $rails_gem_installer
+ puts %{These gems that this application depends on are missing:}
+ unloaded_gems.each do |gem|
+ puts " - #{gem.name}"
+ end
+ puts %{Run "rake gems:install" to install them.}
+ end
+ else
+ @gems_dependencies_loaded = true
+ end
end
# Loads all plugins in <tt>config.plugin_paths</tt>. <tt>plugin_paths</tt>
@@ -287,12 +307,8 @@ module Rails
end
def load_observers
- if configuration.frameworks.include?(:active_record)
- if @configuration.gems.any? { |g| !g.loaded? }
- puts %{Unable to instantiate observers, some gems that this application depends on are missing. Run "rake gems:install"}
- else
- ActiveRecord::Base.instantiate_observers
- end
+ if @gems_dependencies_loaded && configuration.frameworks.include?(:active_record)
+ ActiveRecord::Base.instantiate_observers
end
end
@@ -447,14 +463,18 @@ module Rails
# Fires the user-supplied after_initialize block (Configuration#after_initialize)
def after_initialize
- configuration.after_initialize_blocks.each do |block|
- block.call
+ if @gems_dependencies_loaded
+ configuration.after_initialize_blocks.each do |block|
+ block.call
+ end
end
end
def load_application_initializers
- Dir["#{configuration.root_path}/config/initializers/**/*.rb"].sort.each do |initializer|
- load(initializer)
+ if @gems_dependencies_loaded
+ Dir["#{configuration.root_path}/config/initializers/**/*.rb"].sort.each do |initializer|
+ load(initializer)
+ end
end
end
diff --git a/railties/lib/rails/gem_dependency.rb b/railties/lib/rails/gem_dependency.rb
index 2034841cd2..9f088a18dd 100644
--- a/railties/lib/rails/gem_dependency.rb
+++ b/railties/lib/rails/gem_dependency.rb
@@ -31,12 +31,13 @@ module Rails
args << @requirement.to_s if @requirement
gem *args
else
- $LOAD_PATH << File.join(unpacked_paths.first, 'lib')
+ $LOAD_PATH.unshift File.join(unpacked_paths.first, 'lib')
+ ext = File.join(unpacked_paths.first, 'ext')
+ $LOAD_PATH.unshift(ext) if File.exist?(ext)
@frozen = true
end
@load_paths_added = true
rescue Gem::LoadError
- puts $!.to_s
end
def dependencies
@@ -73,7 +74,9 @@ module Rails
end
def install
- Gem::GemRunner.new.run(install_command)
+ cmd = "#{gem_command} #{install_command.join(' ')}"
+ puts cmd
+ puts %x(#{cmd})
end
def unpack_to(directory)
@@ -100,10 +103,14 @@ private ###################################################################
def specification
@spec ||= Gem.source_index.search(Gem::Dependency.new(@name, @requirement)).sort_by { |s| s.version }.last
end
+
+ def gem_command
+ RUBY_PLATFORM =~ /win32/ ? 'gem.bat' : 'gem'
+ end
def install_command
cmd = %w(install) << @name
- cmd << "--version" << "#{@requirement.to_s}" if @requirement
+ cmd << "--version" << %("#{@requirement.to_s}") if @requirement
cmd << "--source" << @source if @source
cmd
end
diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb
index 04f7e37a20..256f4b0132 100644
--- a/railties/lib/rails/plugin.rb
+++ b/railties/lib/rails/plugin.rb
@@ -98,23 +98,18 @@ module Rails
end
end
- # This Plugin subclass represents a Gem plugin. It behaves exactly like a
- # "traditional" Rails plugin, but doesn't expose any additional load paths,
- # since RubyGems has already taken care of things.
+ # 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)
- super(File.join(spec.full_gem_path, "rails"))
+ super(File.join(spec.full_gem_path))
@name = spec.name
end
- def valid?
- true
- end
-
- def load_paths
- []
+ def init_path
+ File.join(directory, 'rails', 'init.rb')
end
end
end \ No newline at end of file
diff --git a/railties/lib/rails/rack.rb b/railties/lib/rails/rack.rb
new file mode 100644
index 0000000000..abcd0741bf
--- /dev/null
+++ b/railties/lib/rails/rack.rb
@@ -0,0 +1,5 @@
+module Rails
+ module Rack
+ autoload :Static, "rails/rack/static"
+ end
+end
diff --git a/railties/lib/rails/rack/static.rb b/railties/lib/rails/rack/static.rb
new file mode 100644
index 0000000000..45eb0e5921
--- /dev/null
+++ b/railties/lib/rails/rack/static.rb
@@ -0,0 +1,35 @@
+module Rails
+ module Rack
+ class Static
+ FILE_METHODS = %w(GET HEAD).freeze
+
+ def initialize(app)
+ @app = app
+ @file_server = ::Rack::File.new(File.join(RAILS_ROOT, "public"))
+ end
+
+ def call(env)
+ path = env['PATH_INFO'].chomp('/')
+ method = env['REQUEST_METHOD']
+ cached_path = (path.empty? ? 'index' : path) + ::ActionController::Base.page_cache_extension
+
+ if FILE_METHODS.include?(method)
+ if file_exist?(path)
+ return @file_server.call(env)
+ elsif file_exist?(cached_path)
+ env['PATH_INFO'] = cached_path
+ return @file_server.call(env)
+ end
+ end
+
+ @app.call(env)
+ end
+
+ private
+ def file_exist?(path)
+ full_path = File.join(@file_server.root, ::Rack::Utils.unescape(path))
+ File.file?(full_path) && File.readable?(full_path)
+ end
+ end
+ end
+end
diff --git a/railties/lib/rails/version.rb b/railties/lib/rails/version.rb
index fea63beea9..48d24da52e 100644
--- a/railties/lib/rails/version.rb
+++ b/railties/lib/rails/version.rb
@@ -1,8 +1,8 @@
module Rails
module VERSION #:nodoc:
MAJOR = 2
- MINOR = 0
- TINY = 991
+ MINOR = 1
+ TINY = 0
STRING = [MAJOR, MINOR, TINY].join('.')
end
diff --git a/railties/lib/rails_generator/commands.rb b/railties/lib/rails_generator/commands.rb
index 03b7d354a6..08ecbfb5cf 100644
--- a/railties/lib/rails_generator/commands.rb
+++ b/railties/lib/rails_generator/commands.rb
@@ -380,12 +380,14 @@ HELP
# Thanks to Florian Gross (flgr).
def raise_class_collision(class_name)
message = <<end_message
- The name '#{class_name}' is reserved by Ruby on Rails.
+ The name '#{class_name}' is either already used in your application or reserved by Ruby on Rails.
Please choose an alternative and run this generator again.
end_message
if suggest = find_synonyms(class_name)
- message << "\n Suggestions: \n\n"
- message << suggest.join("\n")
+ if suggest.any?
+ message << "\n Suggestions: \n\n"
+ message << suggest.join("\n")
+ end
end
raise UsageError, message
end
diff --git a/railties/lib/tasks/gems.rake b/railties/lib/tasks/gems.rake
index c18fea2d60..0321e60e0f 100644
--- a/railties/lib/tasks/gems.rake
+++ b/railties/lib/tasks/gems.rake
@@ -1,5 +1,5 @@
desc "List the gems that this rails application depends on"
-task :gems => :environment do
+task :gems => 'gems:base' do
Rails.configuration.gems.each do |gem|
code = gem.loaded? ? (gem.frozen? ? "F" : "I") : " "
puts "[#{code}] #{gem.name} #{gem.requirement.to_s}"
@@ -10,8 +10,14 @@ task :gems => :environment do
end
namespace :gems do
+ task :base do
+ $rails_gem_installer = true
+ Rake::Task[:environment].invoke
+ end
+
desc "Build any native extensions for unpacked gems"
task :build do
+ $rails_gem_installer = true
require 'rails/gem_builder'
Dir[File.join(RAILS_ROOT, 'vendor', 'gems', '*')].each do |gem_dir|
spec_file = File.join(gem_dir, '.specification')
@@ -24,14 +30,14 @@ namespace :gems do
end
desc "Installs all required gems for this application."
- task :install => :environment do
+ task :install => :base do
require 'rubygems'
require 'rubygems/gem_runner'
Rails.configuration.gems.each { |gem| gem.install unless gem.loaded? }
end
desc "Unpacks the specified gem into vendor/gems."
- task :unpack => :environment do
+ task :unpack => :base do
require 'rubygems'
require 'rubygems/gem_runner'
Rails.configuration.gems.each do |gem|