Sha256: 4e3a6ec2d2e206b8bfe0b3d17be36b7679da0f9fbe99a8cfb15c206dddb4f0ec

Contents?: true

Size: 1.32 KB

Versions: 31

Compression:

Stored size: 1.32 KB

Contents

require 'active_support/deprecation'
require 'active_support/core_ext/string/strip' # for strip_heredoc
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)
  if ARGV.any?{ |argv| argv.start_with? 'CONTROLLER' }
    puts <<-eow.strip_heredoc
      Passing `CONTROLLER` to `bin/rails routes` is deprecated and will be removed in Rails 5.1.
      Please use `bin/rails routes -c controller_name` instead.
    eow
  end

  routes_filter = nil
  routes_filter = { controller: ENV['CONTROLLER'] } if ENV['CONTROLLER']

  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

31 entries across 31 versions & 4 rubygems

Version Path
railties-5.0.7.2 lib/rails/tasks/routes.rake
railties-5.0.7.1 lib/rails/tasks/routes.rake
railties-5.0.7 lib/rails/tasks/routes.rake
railties-5.0.6 lib/rails/tasks/routes.rake
railties-5.0.6.rc1 lib/rails/tasks/routes.rake
railties-5.0.5 lib/rails/tasks/routes.rake
railties-5.0.5.rc2 lib/rails/tasks/routes.rake
railties-5.0.5.rc1 lib/rails/tasks/routes.rake
railties-5.0.4 lib/rails/tasks/routes.rake
railties-5.0.4.rc1 lib/rails/tasks/routes.rake
railties-5.0.3 lib/rails/tasks/routes.rake
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/railties-5.0.2/lib/rails/tasks/routes.rake
railties-5.0.2 lib/rails/tasks/routes.rake
railties-5.0.2.rc1 lib/rails/tasks/routes.rake
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/tasks/routes.rake
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/tasks/routes.rake
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/tasks/routes.rake
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/tasks/routes.rake
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/tasks/routes.rake
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/tasks/routes.rake