Sha256: 15e48038cf71ef50162a80f9caa8ed2f519496186eef6fcbee23478dfb9c2492

Contents?: true

Size: 918 Bytes

Versions: 20

Compression:

Stored size: 918 Bytes

Contents

require "optparse"

desc "Print out all defined routes in match order, with names. Target specific controller with -c option, or grep routes using -g option"
task routes: :environment do
  all_routes = Rails.application.routes.routes
  require "action_dispatch/routing/inspector"
  inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes)

  routes_filter = nil

  OptionParser.new do |opts|
    opts.banner = "Usage: rails routes [options]"

    Rake.application.standard_rake_options.each { |args| opts.on(*args) }

    opts.on("-c CONTROLLER") do |controller|
      routes_filter = { controller: controller }
    end

    opts.on("-g PATTERN") do |pattern|
      routes_filter = pattern
    end

  end.parse!(ARGV.reject { |x| x == "routes" })

  puts inspector.format(ActionDispatch::Routing::ConsoleFormatter.new, routes_filter)

  exit 0 # ensure extra arguments aren't interpreted as Rake tasks
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
railties-5.1.7 lib/rails/tasks/routes.rake
railties-5.1.7.rc1 lib/rails/tasks/routes.rake
railties-5.1.6.2 lib/rails/tasks/routes.rake
railties-5.1.6.1 lib/rails/tasks/routes.rake
railties-5.1.6 lib/rails/tasks/routes.rake
railties-5.1.5 lib/rails/tasks/routes.rake
railties-5.1.5.rc1 lib/rails/tasks/routes.rake
railties-5.1.4 lib/rails/tasks/routes.rake
railties-5.1.4.rc1 lib/rails/tasks/routes.rake
railties-5.1.3 lib/rails/tasks/routes.rake
railties-5.1.3.rc3 lib/rails/tasks/routes.rake
railties-5.1.3.rc2 lib/rails/tasks/routes.rake
railties-5.1.3.rc1 lib/rails/tasks/routes.rake
railties-5.1.2 lib/rails/tasks/routes.rake
railties-5.1.2.rc1 lib/rails/tasks/routes.rake
railties-5.1.1 lib/rails/tasks/routes.rake
railties-5.1.0 lib/rails/tasks/routes.rake
railties-5.1.0.rc2 lib/rails/tasks/routes.rake
railties-5.1.0.rc1 lib/rails/tasks/routes.rake
railties-5.1.0.beta1 lib/rails/tasks/routes.rake