aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/commands/routes/routes_command.rb
diff options
context:
space:
mode:
authorBenoit Tigeot <benoit@hopsandfork.com>2018-02-26 22:10:12 +0100
committerBenoit Tigeot <benoit@hopsandfork.com>2018-02-27 15:22:38 +0100
commita2748eda586b11db59e2d0f59ab37910156d6c32 (patch)
tree3e6a74c969d899dd6a2636ec305ffad83d9df80f /railties/lib/rails/commands/routes/routes_command.rb
parent87de79e9cc25fe6ac02095a1d0c014941a39ede8 (diff)
downloadrails-a2748eda586b11db59e2d0f59ab37910156d6c32.tar.gz
rails-a2748eda586b11db59e2d0f59ab37910156d6c32.tar.bz2
rails-a2748eda586b11db59e2d0f59ab37910156d6c32.zip
Move rake routes task to rails command
After a discussion with matthewd. It was mentioned that rake tasks need to be moved to rails command. See: https://github.com/rails/rails/issues/32117
Diffstat (limited to 'railties/lib/rails/commands/routes/routes_command.rb')
-rw-r--r--railties/lib/rails/commands/routes/routes_command.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/railties/lib/rails/commands/routes/routes_command.rb b/railties/lib/rails/commands/routes/routes_command.rb
new file mode 100644
index 0000000000..c4fd6c7eb5
--- /dev/null
+++ b/railties/lib/rails/commands/routes/routes_command.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+require "rails/command"
+
+module Rails
+ module Command
+ class RoutesCommand < Base # :nodoc:
+ class_option :controller, aliases: "-c", type: :string, desc: "Specifies the controller."
+ class_option :grep_pattern, aliases: "-g", type: :string, desc: "Specifies grep pattern."
+
+ no_commands do
+ def help
+ say "Usage: Print out all defined routes in match order, with names."
+ say ""
+ say "Target specific controller with -c option, or grep routes using -g option"
+ say ""
+ end
+ end
+
+ def perform(*)
+ require_application_and_environment!
+ require "action_dispatch/routing/inspector"
+
+ all_routes = Rails.application.routes.routes
+ inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes)
+
+ say inspector.format(ActionDispatch::Routing::ConsoleFormatter.new, routes_filter)
+ end
+
+ private
+
+ def routes_filter
+ if options.has_key?("controller")
+ { controller: options["controller"] }
+ elsif options.has_key?("grep_pattern")
+ options["grep_pattern"]
+ else
+ nil
+ end
+ end
+ end
+ end
+end