aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/rails/application.rb6
-rw-r--r--railties/lib/rails/application/configuration.rb5
-rw-r--r--railties/lib/rails/application/finisher.rb4
-rw-r--r--railties/lib/rails/code_statistics.rb2
-rw-r--r--railties/lib/rails/commands/runner.rb4
-rw-r--r--railties/lib/rails/engine.rb48
-rw-r--r--railties/lib/rails/engine/configuration.rb1
-rw-r--r--railties/lib/rails/generators.rb5
-rw-r--r--railties/lib/rails/generators/migration.rb6
-rw-r--r--railties/lib/rails/generators/test_case.rb20
-rw-r--r--railties/lib/rails/info_routes.rb3
-rw-r--r--railties/lib/rails/ruby_version_check.rb3
12 files changed, 64 insertions, 43 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index b923fedab7..0e85e6d1d5 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -147,9 +147,11 @@ module Rails
def default_middleware_stack
ActionDispatch::MiddlewareStack.new.tap do |middleware|
- require "action_dispatch/http/rack_cache" if config.action_dispatch.rack_cache
+ rack_cache = config.action_controller.perform_caching && config.action_dispatch.rack_cache
- middleware.use ::Rack::Cache, config.action_dispatch.rack_cache if config.action_dispatch.rack_cache
+ require "action_dispatch/http/rack_cache" if rack_cache
+
+ middleware.use ::Rack::Cache, rack_cache if rack_cache
middleware.use ::ActionDispatch::Static, config.static_asset_paths if config.serve_static_assets
middleware.use ::Rack::Lock if !config.allow_concurrency
middleware.use ::Rack::Runtime
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index f9f06299a0..a0ecbc0fc8 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -59,7 +59,6 @@ module Rails
def paths
@paths ||= begin
paths = super
- paths.app.controllers << builtin_controller if builtin_controller
paths.config.database "config/database.yml"
paths.config.environment "config/environment.rb"
paths.lib.templates "lib/templates"
@@ -101,10 +100,6 @@ module Rails
end
end
- def builtin_controller
- File.expand_path('../info_routes', __FILE__) if Rails.env.development?
- end
-
def log_level
@log_level ||= Rails.env.production? ? :info : :debug
end
diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb
index 8fd2aa0bce..b95df467c7 100644
--- a/railties/lib/rails/application/finisher.rb
+++ b/railties/lib/rails/application/finisher.rb
@@ -27,7 +27,9 @@ module Rails
initializer :add_builtin_route do |app|
if Rails.env.development?
- app.routes_reloader.paths << File.expand_path('../../info_routes.rb', __FILE__)
+ app.routes.append do
+ match '/rails/info/properties' => "rails/info#properties"
+ end
end
end
diff --git a/railties/lib/rails/code_statistics.rb b/railties/lib/rails/code_statistics.rb
index 57e29a0045..78a4f00ad8 100644
--- a/railties/lib/rails/code_statistics.rb
+++ b/railties/lib/rails/code_statistics.rb
@@ -23,7 +23,7 @@ class CodeStatistics #:nodoc:
private
def calculate_statistics
- @pairs.inject({}) { |stats, pair| stats[pair.first] = calculate_directory_statistics(pair.last); stats }
+ Hash[@pais.mapĀ { |pair| [pair.first, calculate_directory_statistics(pair.last)] }]
end
def calculate_directory_statistics(directory, pattern = /.*\.rb$/)
diff --git a/railties/lib/rails/commands/runner.rb b/railties/lib/rails/commands/runner.rb
index 54a9e6ec59..1a91d477ec 100644
--- a/railties/lib/rails/commands/runner.rb
+++ b/railties/lib/rails/commands/runner.rb
@@ -17,13 +17,13 @@ ARGV.clone.options do |opts|
opts.separator ""
opts.on("-h", "--help",
- "Show this help message.") { $stderr.puts opts; exit }
+ "Show this help message.") { $stdout.puts opts; exit }
if RbConfig::CONFIG['host_os'] !~ /mswin|mingw/
opts.separator ""
opts.separator "You can also use runner as a shebang line for your scripts like this:"
opts.separator "-------------------------------------------------------------"
- opts.separator "#!/usr/bin/env #{File.expand_path($0)}"
+ opts.separator "#!/usr/bin/env #{File.expand_path($0)} runner"
opts.separator ""
opts.separator "Product.find(:all).each { |p| p.price *= 2 ; p.save! }"
opts.separator "-------------------------------------------------------------"
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index 10df9b3a6c..0620b8608e 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -211,12 +211,30 @@ module Rails
# end
# end
#
- # If engine is marked as namespaced, FooController has access only to helpers from engine and
+ # If engine is marked as isolated, FooController has access only to helpers from engine and
# url_helpers from MyEngine::Engine.routes.
#
+ # The next thing that changes in isolated engine is routes behaviour. Normally, when you namespace
+ # your controllers, you need to use scope or namespace method in routes. With isolated engine,
+ # the namespace is applied by default, so you can ignore it in routes. Further more, you don't need
+ # to use longer url helpers like "my_engine_articles_path". As the prefix is not set you can just use
+ # articles_path as you would normally do.
+ #
+ # To make that behaviour consistent with other parts of framework, isolated engine has influence also on
+ # ActiveModel::Naming. When you use namespaced model, like MyEngine::Article, it will normally
+ # use the prefix "my_engine". In isolated engine, the prefix will be ommited in most of the places,
+ # like url helpers or form fields.
+ #
+ # polymorphic_url(MyEngine::Article.new) #=> "articles_path"
+ #
+ # form_for(MyEngine::Article.new) do
+ # text_field :title #=> <input type="text" name="article[title]" id="article_title" />
+ # end
+ #
+ #
# Additionaly namespaced engine will set its name according to namespace, so in that case:
- # MyEngine::Engine.engine_name #=> "my_engine"
- # and it will set MyEngine.table_name_prefix to "my_engine_"
+ # MyEngine::Engine.engine_name #=> "my_engine" and it will set MyEngine.table_name_prefix
+ # to "my_engine_".
#
# == Using Engine's routes outside Engine
#
@@ -257,6 +275,21 @@ module Rails
#
# This code will use my_engine.user_path(@user) to generate proper route.
#
+ # == Migrations & seed data
+ #
+ # Engines can have their own migrations. Default path for migrations is exactly the same
+ # as in application: db/migrate
+ #
+ # To use engine's migrations in application you can use rake task, which copies them to
+ # application's dir:
+ #
+ # rake railties:copy_migrations
+ #
+ # If your engine has migrations, you may also want to prepare data for the database in
+ # seeds.rb file. You can load that data using load_seed method, e.g.
+ #
+ # MyEngine::Engine.load_seed
+ #
class Engine < Railtie
autoload :Configurable, "rails/engine/configurable"
autoload :Configuration, "rails/engine/configuration"
@@ -380,6 +413,15 @@ module Rails
@config ||= Engine::Configuration.new(find_root_with_flag("lib"))
end
+ # Load data from db/seeds.rb file. It can be used in to load engines'
+ # seeds, e.g.:
+ #
+ # Blog::Engine.load_seed
+ def load_seed
+ seed_file = config.paths.db.seeds.to_a.first
+ load(seed_file) if File.exist?(seed_file)
+ end
+
# Add configured load paths to ruby load paths and remove duplicates.
initializer :set_load_path, :before => :bootstrap_hook do
_all_load_paths.reverse_each do |path|
diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb
index 3ac8911ba8..d4d87be527 100644
--- a/railties/lib/rails/engine/configuration.rb
+++ b/railties/lib/rails/engine/configuration.rb
@@ -37,6 +37,7 @@ module Rails
paths.vendor.plugins "vendor/plugins"
paths.db "db"
paths.db.migrate "db/migrate"
+ paths.db.seeds "db/seeds.rb"
paths
end
end
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index 76ef598d68..240810b8bd 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -140,10 +140,7 @@ module Rails
lookup(lookups)
- namespaces = subclasses.inject({}) do |hash, klass|
- hash[klass.namespace] = klass
- hash
- end
+ namespaces = Hash[subclasses.map { |klass| [klass.namespace, klass] }]
lookups.each do |namespace|
klass = namespaces[namespace]
diff --git a/railties/lib/rails/generators/migration.rb b/railties/lib/rails/generators/migration.rb
index 9244307261..8d98909055 100644
--- a/railties/lib/rails/generators/migration.rb
+++ b/railties/lib/rails/generators/migration.rb
@@ -53,7 +53,11 @@ module Rails
destination = self.class.migration_exists?(migration_dir, @migration_file_name)
if behavior == :invoke
- raise Error, "Another migration is already named #{@migration_file_name}: #{destination}" if destination
+ if destination && options.force?
+ remove_file(destination)
+ elsif destination
+ raise Error, "Another migration is already named #{@migration_file_name}: #{destination}"
+ end
destination = File.join(migration_dir, "#{@migration_number}_#{@migration_file_name}.rb")
end
diff --git a/railties/lib/rails/generators/test_case.rb b/railties/lib/rails/generators/test_case.rb
index 3376b422cb..cab8708be3 100644
--- a/railties/lib/rails/generators/test_case.rb
+++ b/railties/lib/rails/generators/test_case.rb
@@ -1,6 +1,7 @@
require 'active_support/core_ext/class/attribute'
require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/hash/reverse_merge'
+require 'active_support/core_ext/kernel/reporting'
require 'rails/generators'
require 'fileutils'
@@ -65,25 +66,6 @@ module Rails
self.destination_root = path
end
- # Captures the given stream and returns it:
- #
- # stream = capture(:stdout){ puts "Cool" }
- # stream # => "Cool\n"
- #
- def capture(stream)
- begin
- stream = stream.to_s
- eval "$#{stream} = StringIO.new"
- yield
- result = eval("$#{stream}").string
- ensure
- eval("$#{stream} = #{stream.upcase}")
- end
-
- result
- end
- alias :silence :capture
-
# Asserts a given file exists. You need to supply an absolute path or a path relative
# to the configured destination:
#
diff --git a/railties/lib/rails/info_routes.rb b/railties/lib/rails/info_routes.rb
deleted file mode 100644
index b5c4e4c1e0..0000000000
--- a/railties/lib/rails/info_routes.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-Rails.application.routes.draw do
- match '/rails/info/properties' => "rails/info#properties"
-end
diff --git a/railties/lib/rails/ruby_version_check.rb b/railties/lib/rails/ruby_version_check.rb
index e8d1d1e039..4d57c5973c 100644
--- a/railties/lib/rails/ruby_version_check.rb
+++ b/railties/lib/rails/ruby_version_check.rb
@@ -14,8 +14,7 @@ elsif RUBY_VERSION > '1.9' and RUBY_VERSION < '1.9.2'
$stderr.puts <<-end_message
Rails 3 doesn't officially support Ruby 1.9.1 since recent stable
- releases have segfaulted the test suite. Please upgrade to Ruby 1.9.2
- before Rails 3 is released!
+ releases have segfaulted the test suite. Please upgrade to Ruby 1.9.2.
You're running
#{RUBY_DESCRIPTION}