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/annotations.rake20
-rw-r--r--railties/lib/rails/tasks/documentation.rake70
-rw-r--r--railties/lib/rails/tasks/engine.rake72
-rw-r--r--railties/lib/rails/tasks/framework.rake66
-rw-r--r--railties/lib/rails/tasks/log.rake23
-rw-r--r--railties/lib/rails/tasks/middleware.rake7
-rw-r--r--railties/lib/rails/tasks/misc.rake60
-rw-r--r--railties/lib/rails/tasks/routes.rake7
-rw-r--r--railties/lib/rails/tasks/statistics.rake27
-rw-r--r--railties/lib/rails/tasks/tmp.rake45
10 files changed, 397 insertions, 0 deletions
diff --git a/railties/lib/rails/tasks/annotations.rake b/railties/lib/rails/tasks/annotations.rake
new file mode 100644
index 0000000000..386ecf44be
--- /dev/null
+++ b/railties/lib/rails/tasks/annotations.rake
@@ -0,0 +1,20 @@
+require 'rails/source_annotation_extractor'
+
+desc "Enumerate all annotations (use notes:optimize, :fixme, :todo for focus)"
+task :notes do
+ SourceAnnotationExtractor.enumerate "OPTIMIZE|FIXME|TODO", tag: true
+end
+
+namespace :notes do
+ ["OPTIMIZE", "FIXME", "TODO"].each do |annotation|
+ # desc "Enumerate all #{annotation} annotations"
+ task annotation.downcase.intern do
+ SourceAnnotationExtractor.enumerate annotation
+ end
+ end
+
+ desc "Enumerate a custom annotation, specify with ANNOTATION=CUSTOM"
+ task :custom do
+ SourceAnnotationExtractor.enumerate ENV['ANNOTATION']
+ end
+end \ No newline at end of file
diff --git a/railties/lib/rails/tasks/documentation.rake b/railties/lib/rails/tasks/documentation.rake
new file mode 100644
index 0000000000..8544890553
--- /dev/null
+++ b/railties/lib/rails/tasks/documentation.rake
@@ -0,0 +1,70 @@
+begin
+ require 'rdoc/task'
+rescue LoadError
+ # Rubinius installs RDoc as a gem, and for this interpreter "rdoc/task" is
+ # available only if the application bundle includes "rdoc" (normally as a
+ # dependency of the "sdoc" gem.)
+ #
+ # If RDoc is not available it is fine that we do not generate the tasks that
+ # depend on it. Just be robust to this gotcha and go on.
+else
+ require 'rails/api/task'
+
+ # Monkey-patch to remove redoc'ing and clobber descriptions to cut down on rake -T noise
+ class RDocTaskWithoutDescriptions < RDoc::Task
+ include ::Rake::DSL
+
+ 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
+ rm_r @rdoc_dir rescue nil
+ @before_running_rdoc.call if @before_running_rdoc
+ args = option_list + @rdoc_files
+ if @external
+ argstring = args.join(' ')
+ sh %{ruby -Ivendor vendor/rd #{argstring}}
+ else
+ require 'rdoc/rdoc'
+ RDoc::RDoc.new.document(args)
+ end
+ end
+ self
+ end
+ end
+
+ namespace :doc do
+ RDocTaskWithoutDescriptions.new("app") { |rdoc|
+ rdoc.rdoc_dir = 'doc/app'
+ rdoc.template = ENV['template'] if ENV['template']
+ rdoc.title = ENV['title'] || "Rails Application Documentation"
+ rdoc.options << '--line-numbers'
+ rdoc.options << '--charset' << 'utf-8'
+ rdoc.rdoc_files.include('README.rdoc')
+ rdoc.rdoc_files.include('app/**/*.rb')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+ }
+ Rake::Task['doc:app'].comment = "Generate docs for the app -- also available doc:rails, doc:guides (options: TEMPLATE=/rdoc-template.rb, TITLE=\"Custom Title\")"
+
+ # desc 'Generate documentation for the Rails framework.'
+ Rails::API::AppTask.new('rails')
+ end
+end
+
+namespace :doc do
+ task :guides do
+ rails_gem_dir = Gem::Specification.find_by_name("rails").gem_dir
+ require File.expand_path(File.join(rails_gem_dir, "/guides/rails_guides"))
+ RailsGuides::Generator.new(Rails.root.join("doc/guides")).generate
+ end
+end
diff --git a/railties/lib/rails/tasks/engine.rake b/railties/lib/rails/tasks/engine.rake
new file mode 100644
index 0000000000..16ad1bfc84
--- /dev/null
+++ b/railties/lib/rails/tasks/engine.rake
@@ -0,0 +1,72 @@
+task "load_app" do
+ namespace :app do
+ load APP_RAKEFILE
+ end
+ task :environment => "app:environment"
+
+ 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 databases 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 File.expand_path(Dir.pwd) if path == "/"
+
+ if Rails::Engine.find(path)
+ path
+ else
+ find_engine_path(File.expand_path('..', path))
+ end
+end
+
+Rake.application.invoke_task(:load_app)
diff --git a/railties/lib/rails/tasks/framework.rake b/railties/lib/rails/tasks/framework.rake
new file mode 100644
index 0000000000..a1c805f8aa
--- /dev/null
+++ b/railties/lib/rails/tasks/framework.rake
@@ -0,0 +1,66 @@
+namespace :rails do
+ desc "Update configs and some other initially generated files (or use just update:configs or update:bin)"
+ task update: [ "update:configs", "update:bin" ]
+
+ desc "Applies the template supplied by LOCATION=(/path/to/template) or URL"
+ task template: :environment do
+ template = ENV["LOCATION"]
+ raise "No LOCATION value given. Please set LOCATION either as path to a file or a URL" if template.blank?
+ template = File.expand_path(template) if template !~ %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://}
+ require 'rails/generators'
+ require 'rails/generators/rails/app/app_generator'
+ generator = Rails::Generators::AppGenerator.new [Rails.root], {}, destination_root: Rails.root
+ generator.apply template, verbose: false
+ end
+
+ namespace :templates do
+ # desc "Copy all the templates from rails to the application directory for customization. Already existing local copies will be overwritten"
+ task :copy do
+ generators_lib = File.expand_path("../../generators", __FILE__)
+ project_templates = "#{Rails.root}/lib/templates"
+
+ default_templates = { "erb" => %w{controller mailer scaffold},
+ "rails" => %w{controller helper scaffold_controller assets} }
+
+ default_templates.each do |type, names|
+ local_template_type_dir = File.join(project_templates, type)
+ FileUtils.mkdir_p local_template_type_dir
+
+ names.each do |name|
+ dst_name = File.join(local_template_type_dir, name)
+ src_name = File.join(generators_lib, type, name, "templates")
+ FileUtils.cp_r src_name, dst_name
+ end
+ end
+ end
+ end
+
+ namespace :update do
+ def invoke_from_app_generator(method)
+ app_generator.send(method)
+ end
+
+ def app_generator
+ @app_generator ||= begin
+ require 'rails/generators'
+ require 'rails/generators/rails/app/app_generator'
+ gen = Rails::Generators::AppGenerator.new ["rails"], { with_dispatchers: true },
+ destination_root: Rails.root
+ File.exist?(Rails.root.join("config", "application.rb")) ?
+ gen.send(:app_const) : gen.send(:valid_const?)
+ gen
+ end
+ end
+
+ # desc "Update config/boot.rb from your current rails install"
+ task :configs do
+ invoke_from_app_generator :create_boot_file
+ invoke_from_app_generator :update_config_files
+ end
+
+ # desc "Adds new executables to the application bin/ directory"
+ task :bin do
+ invoke_from_app_generator :create_bin_files
+ end
+ end
+end
diff --git a/railties/lib/rails/tasks/log.rake b/railties/lib/rails/tasks/log.rake
new file mode 100644
index 0000000000..877f175ef3
--- /dev/null
+++ b/railties/lib/rails/tasks/log.rake
@@ -0,0 +1,23 @@
+namespace :log do
+ desc "Truncates all *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)"
+ task :clear do
+ log_files.each do |file|
+ clear_log_file(file)
+ end
+ end
+
+ def log_files
+ if ENV['LOGS']
+ ENV['LOGS'].split(',')
+ .map { |file| "log/#{file.strip}.log" }
+ .select { |file| File.exist?(file) }
+ else
+ FileList["log/*.log"]
+ end
+ end
+
+ def clear_log_file(file)
+ f = File.open(file, "w")
+ f.close
+ end
+end
diff --git a/railties/lib/rails/tasks/middleware.rake b/railties/lib/rails/tasks/middleware.rake
new file mode 100644
index 0000000000..31e961b483
--- /dev/null
+++ b/railties/lib/rails/tasks/middleware.rake
@@ -0,0 +1,7 @@
+desc 'Prints out your Rack middleware stack'
+task middleware: :environment do
+ Rails.configuration.middleware.each do |middleware|
+ puts "use #{middleware.inspect}"
+ end
+ puts "run #{Rails.application.class.name}.routes"
+end
diff --git a/railties/lib/rails/tasks/misc.rake b/railties/lib/rails/tasks/misc.rake
new file mode 100644
index 0000000000..4195106961
--- /dev/null
+++ b/railties/lib/rails/tasks/misc.rake
@@ -0,0 +1,60 @@
+desc 'Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions).'
+task :secret do
+ require 'securerandom'
+ puts SecureRandom.hex(64)
+end
+
+desc 'List versions of all Rails frameworks and the environment'
+task about: :environment do
+ puts Rails::Info
+end
+
+namespace :time do
+ namespace :zones do
+ desc 'Displays all time zones, also available: time:zones:us, time:zones:local -- filter with OFFSET parameter, e.g., OFFSET=-6'
+ task :all do
+ build_time_zone_list(:all)
+ end
+
+ # desc 'Displays names of US time zones recognized by the Rails TimeZone class, grouped by offset. Results can be filtered with optional OFFSET parameter, e.g., OFFSET=-6'
+ task :us do
+ build_time_zone_list(:us_zones)
+ end
+
+ # desc 'Displays names of time zones recognized by the Rails TimeZone class with the same offset as the system local time'
+ task :local do
+ require 'active_support'
+ require 'active_support/time'
+ jan_offset = Time.now.beginning_of_year.utc_offset
+ jul_offset = Time.now.beginning_of_year.change(month: 7).utc_offset
+ offset = jan_offset < jul_offset ? jan_offset : jul_offset
+ build_time_zone_list(:all, offset)
+ end
+
+ # to find UTC -06:00 zones, OFFSET can be set to either -6, -6:00 or 21600
+ def build_time_zone_list(method, offset = ENV['OFFSET'])
+ require 'active_support'
+ require 'active_support/time'
+ if offset
+ offset = if offset.to_s.match(/(\+|-)?(\d+):(\d+)/)
+ sign = $1 == '-' ? -1 : 1
+ hours, minutes = $2.to_f, $3.to_f
+ ((hours * 3600) + (minutes.to_f * 60)) * sign
+ elsif offset.to_f.abs <= 13
+ offset.to_f * 3600
+ else
+ offset.to_f
+ end
+ end
+ previous_offset = nil
+ ActiveSupport::TimeZone.__send__(method).each do |zone|
+ if offset.nil? || offset == zone.utc_offset
+ puts "\n* UTC #{zone.formatted_offset} *" unless zone.utc_offset == previous_offset
+ puts zone.name
+ previous_offset = zone.utc_offset
+ end
+ end
+ puts "\n"
+ end
+ end
+end
diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake
new file mode 100644
index 0000000000..1815c2fdc7
--- /dev/null
+++ b/railties/lib/rails/tasks/routes.rake
@@ -0,0 +1,7 @@
+desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.'
+task routes: :environment do
+ all_routes = Rails.application.routes.routes
+ require 'action_dispatch/routing/inspector'
+ inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes)
+ puts inspector.format(ActionDispatch::Routing::ConsoleFormatter.new, ENV['CONTROLLER'])
+end
diff --git a/railties/lib/rails/tasks/statistics.rake b/railties/lib/rails/tasks/statistics.rake
new file mode 100644
index 0000000000..ae5a7d2759
--- /dev/null
+++ b/railties/lib/rails/tasks/statistics.rake
@@ -0,0 +1,27 @@
+# while having global constant is not good,
+# many 3rd party tools depend on it, like rspec-rails, cucumber-rails, etc
+# so if will be removed - deprecation warning is needed
+STATS_DIRECTORIES = [
+ %w(Controllers app/controllers),
+ %w(Helpers app/helpers),
+ %w(Models app/models),
+ %w(Mailers app/mailers),
+ %w(Javascripts app/assets/javascripts),
+ %w(Libraries lib/),
+ %w(APIs app/apis),
+ %w(Controller\ tests test/controllers),
+ %w(Helper\ tests test/helpers),
+ %w(Model\ tests test/models),
+ %w(Mailer\ tests test/mailers),
+ %w(Integration\ tests test/integration),
+ %w(Functional\ tests\ (old) test/functional),
+ %w(Unit\ tests \ (old) test/unit)
+].collect do |name, dir|
+ [ name, "#{File.dirname(Rake.application.rakefile_location)}/#{dir}" ]
+end.select { |name, dir| File.directory?(dir) }
+
+desc "Report code statistics (KLOCs, etc) from the application or engine"
+task :stats do
+ require 'rails/code_statistics'
+ CodeStatistics.new(*STATS_DIRECTORIES).to_s
+end \ No newline at end of file
diff --git a/railties/lib/rails/tasks/tmp.rake b/railties/lib/rails/tasks/tmp.rake
new file mode 100644
index 0000000000..116988665f
--- /dev/null
+++ b/railties/lib/rails/tasks/tmp.rake
@@ -0,0 +1,45 @@
+namespace :tmp do
+ desc "Clear session, cache, and socket files from tmp/ (narrow w/ tmp:sessions:clear, tmp:cache:clear, tmp:sockets:clear)"
+ task clear: [ "tmp:sessions:clear", "tmp:cache:clear", "tmp:sockets:clear"]
+
+ tmp_dirs = [ 'tmp/sessions',
+ 'tmp/cache',
+ 'tmp/sockets',
+ 'tmp/pids',
+ 'tmp/cache/assets/development',
+ 'tmp/cache/assets/test',
+ 'tmp/cache/assets/production' ]
+
+ tmp_dirs.each { |d| directory d }
+
+ desc "Creates tmp directories for sessions, cache, sockets, and pids"
+ task create: tmp_dirs
+
+ namespace :sessions do
+ # desc "Clears all files in tmp/sessions"
+ task :clear do
+ FileUtils.rm(Dir['tmp/sessions/[^.]*'])
+ end
+ end
+
+ namespace :cache do
+ # desc "Clears all files and directories in tmp/cache"
+ task :clear do
+ FileUtils.rm_rf(Dir['tmp/cache/[^.]*'])
+ end
+ end
+
+ namespace :sockets do
+ # desc "Clears all files in tmp/sockets"
+ task :clear do
+ FileUtils.rm(Dir['tmp/sockets/[^.]*'])
+ end
+ end
+
+ namespace :pids do
+ # desc "Clears all files in tmp/pids"
+ task :clear do
+ FileUtils.rm(Dir['tmp/pids/[^.]*'])
+ end
+ end
+end