aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/rails/tasks')
-rw-r--r--railties/lib/rails/tasks/documentation.rake10
-rw-r--r--railties/lib/rails/tasks/engine.rake69
-rw-r--r--railties/lib/rails/tasks/framework.rake19
-rw-r--r--railties/lib/rails/tasks/misc.rake2
-rw-r--r--railties/lib/rails/tasks/railties.rake29
-rw-r--r--railties/lib/rails/tasks/routes.rake31
6 files changed, 124 insertions, 36 deletions
diff --git a/railties/lib/rails/tasks/documentation.rake b/railties/lib/rails/tasks/documentation.rake
index c1b1a41d48..edd716d7d0 100644
--- a/railties/lib/rails/tasks/documentation.rake
+++ b/railties/lib/rails/tasks/documentation.rake
@@ -4,15 +4,15 @@ require 'rake/rdoctask'
class RDocTaskWithoutDescriptions < Rake::RDocTask
def define
task rdoc_task_name
-
+
task rerdoc_task_name => [clobber_task_name, rdoc_task_name]
-
+
task clobber_task_name do
rm_r rdoc_dir rescue nil
end
-
+
task :clobber => [clobber_task_name]
-
+
directory @rdoc_dir
task rdoc_task_name => [rdoc_target]
file rdoc_target => @rdoc_files + [Rake.application.rakefile] do
@@ -47,7 +47,7 @@ namespace :doc do
rdoc.rdoc_files.include('app/**/*.rb')
rdoc.rdoc_files.include('lib/**/*.rb')
}
- Rake::Task['doc:app'].comment = "Generate docs for the app -- also availble doc:rails, doc:guides, doc:plugins (options: TEMPLATE=/rdoc-template.rb, TITLE=\"Custom Title\")"
+ Rake::Task['doc:app'].comment = "Generate docs for the app -- also available doc:rails, doc:guides, doc:plugins (options: TEMPLATE=/rdoc-template.rb, TITLE=\"Custom Title\")"
# desc 'Generate documentation for the Rails framework.'
RDocTaskWithoutDescriptions.new("rails") { |rdoc|
diff --git a/railties/lib/rails/tasks/engine.rake b/railties/lib/rails/tasks/engine.rake
new file mode 100644
index 0000000000..2f0e7be896
--- /dev/null
+++ b/railties/lib/rails/tasks/engine.rake
@@ -0,0 +1,69 @@
+task "load_app" do
+ namespace :app do
+ load APP_RAKEFILE
+ end
+
+ if !defined?(ENGINE_PATH) || !ENGINE_PATH
+ ENGINE_PATH = find_engine_path(APP_RAKEFILE)
+ end
+end
+
+def app_task(name)
+ task name => [:load_app, "app:db:#{name}"]
+end
+
+namespace :db do
+ app_task "reset"
+
+ desc "Migrate the database (options: VERSION=x, VERBOSE=false)."
+ app_task "migrate"
+ app_task "migrate:up"
+ app_task "migrate:down"
+ app_task "migrate:redo"
+ app_task "migrate:reset"
+
+ desc "Display status of migrations"
+ app_task "migrate:status"
+
+ desc 'Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)'
+ app_task "create"
+ app_task "create:all"
+
+ desc 'Drops the database for the current Rails.env (use db:drop:all to drop all databases)'
+ app_task "drop"
+ app_task "drop:all"
+
+ desc "Load fixtures into the current environment's database."
+ app_task "fixtures:load"
+
+ desc "Rolls the schema back to the previous version (specify steps w/ STEP=n)."
+ app_task "rollback"
+
+ desc "Create a db/schema.rb file that can be portably used against any DB supported by AR"
+ app_task "schema:dump"
+
+ desc "Load a schema.rb file into the database"
+ app_task "schema:load"
+
+ desc "Load the seed data from db/seeds.rb"
+ app_task "seed"
+
+ desc "Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first)"
+ app_task "setup"
+
+ desc "Dump the database structure to an SQL file"
+ app_task "structure:dump"
+
+ desc "Retrieves the current schema version number"
+ app_task "version"
+end
+
+def find_engine_path(path)
+ return if path == "/"
+
+ if Rails::Engine.find(path)
+ path
+ else
+ find_engine_path(File.expand_path('..', path))
+ end
+end
diff --git a/railties/lib/rails/tasks/framework.rake b/railties/lib/rails/tasks/framework.rake
index 443dacd739..5222b7bf50 100644
--- a/railties/lib/rails/tasks/framework.rake
+++ b/railties/lib/rails/tasks/framework.rake
@@ -1,21 +1,4 @@
namespace :rails do
- namespace :freeze do
- # desc "The rails:freeze:gems is deprecated, please use bundle install instead"
- task :gems do
- abort "The rails:freeze:gems is deprecated, please use bundle install instead"
- end
-
- # desc 'The freeze:edge command has been deprecated, specify the path setting in your app Gemfile instead and bundle install'
- task :edge do
- abort 'The freeze:edge command has been deprecated, specify the path setting in your app Gemfile instead and bundle install'
- end
- end
-
- # desc 'The unfreeze command has been deprecated, please use bundler commands instead'
- task :unfreeze do
- abort 'The unfreeze command has been deprecated, please use bundler commands instead'
- end
-
desc "Update both configs and public/javascripts from Rails (or use just update:javascripts or update:configs)"
task :update => [ "update:configs", "update:javascripts", "update:scripts", "update:application_controller" ]
@@ -77,7 +60,7 @@ namespace :rails do
# desc "Update Prototype javascripts from your current rails install"
task :javascripts do
- invoke_from_app_generator :create_prototype_files
+ invoke_from_app_generator :create_javascript_files
end
# desc "Adds new scripts to the application script/ directory"
diff --git a/railties/lib/rails/tasks/misc.rake b/railties/lib/rails/tasks/misc.rake
index c6c22d83bf..e505b8c338 100644
--- a/railties/lib/rails/tasks/misc.rake
+++ b/railties/lib/rails/tasks/misc.rake
@@ -7,7 +7,7 @@ task :rails_env do
end
end
-desc 'Generate a crytographically secure secret key (this is typically used to generate a secret for cookie sessions).'
+desc 'Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions).'
task :secret do
require 'active_support/secure_random'
puts ActiveSupport::SecureRandom.hex(64)
diff --git a/railties/lib/rails/tasks/railties.rake b/railties/lib/rails/tasks/railties.rake
new file mode 100644
index 0000000000..16703879cf
--- /dev/null
+++ b/railties/lib/rails/tasks/railties.rake
@@ -0,0 +1,29 @@
+namespace :railties do
+ namespace :install do
+ # desc "Copies missing assets from Railties (e.g. plugins, engines). You can specify Railties to use with FROM=railtie1,railtie2"
+ task :assets => :rails_env do
+ require 'rails/generators/base'
+ Rails.application.initialize!
+
+ to_load = ENV["FROM"].blank? ? :all : ENV["FROM"].split(",").map {|n| n.strip }
+ app_public_path = Rails.application.paths["public"].first
+
+ Rails.application.railties.all do |railtie|
+ next unless to_load == :all || to_load.include?(railtie.railtie_name)
+
+ if railtie.respond_to?(:paths) && (path = railtie.paths["public"].first) &&
+ (assets_dir = railtie.config.compiled_asset_path) && File.exist?(path)
+
+ Rails::Generators::Base.source_root(path)
+ copier = Rails::Generators::Base.new
+ Dir[File.join(path, "**/*")].each do |file|
+ relative = file.gsub(/^#{path}\//, '')
+ if File.file?(file)
+ copier.copy_file relative, File.join(app_public_path, assets_dir, relative)
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake
index a99232c4be..02e22361e0 100644
--- a/railties/lib/rails/tasks/routes.rake
+++ b/railties/lib/rails/tasks/routes.rake
@@ -1,20 +1,27 @@
desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.'
task :routes => :environment do
Rails.application.reload_routes!
- all_routes = ENV['CONTROLLER'] ? Rails.application.routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : Rails.application.routes.routes
+ all_routes = Rails.application.routes.routes
+
+ if ENV['CONTROLLER']
+ all_routes = all_routes.select{ |route| route.defaults[:controller] == ENV['CONTROLLER'] }
+ end
+
routes = all_routes.collect do |route|
- # TODO: The :index method is deprecated in 1.9 in favor of :key
- # but we don't have :key in 1.8.7. We can remove this check when
- # stop supporting 1.8.x
- key_method = Hash.method_defined?('key') ? 'key' : 'index'
- name = Rails.application.routes.named_routes.routes.send(key_method, route).to_s
- reqs = route.requirements.empty? ? "" : route.requirements.inspect
- {:name => name, :verb => route.verb.to_s, :path => route.path, :reqs => reqs}
+
+ reqs = route.requirements.dup
+ reqs[:to] = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/
+ reqs = reqs.empty? ? "" : reqs.inspect
+
+ {:name => route.name.to_s, :verb => route.verb.to_s, :path => route.path, :reqs => reqs}
end
- routes.reject!{ |r| r[:path] == "/rails/info/properties" } # skip the route if it's internal info route
- name_width = routes.collect {|r| r[:name]}.collect {|n| n.length}.max
- verb_width = routes.collect {|r| r[:verb]}.collect {|v| v.length}.max
- path_width = routes.collect {|r| r[:path]}.collect {|s| s.length}.max
+
+ routes.reject! { |r| r[:path] =~ %r{/rails/info/properties} } # Skip the route if it's internal info route
+
+ name_width = routes.map{ |r| r[:name].length }.max
+ verb_width = routes.map{ |r| r[:verb].length }.max
+ path_width = routes.map{ |r| r[:path].length }.max
+
routes.each do |r|
puts "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}"
end