Sha256: db1efb81906975dbc718ccfd50f2ae322021d466f3fd1eadd8b534ae480a8aae

Contents?: true

Size: 1.44 KB

Versions: 39

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

require "rails/command"

module Rails
  module Command
    class RoutesCommand < Base # :nodoc:
      class_option :controller, aliases: "-c", desc: "Filter by a specific controller, e.g. PostsController or Admin::PostsController."
      class_option :grep, aliases: "-g", desc: "Grep routes by a specific pattern."
      class_option :expanded, type: :boolean, aliases: "-E", desc: "Print routes expanded vertically with parts explained."
      class_option :unused, type: :boolean, aliases: "-u", desc: "Print unused routes."

      no_commands do
        def invoke_command(*)
          if options.key?("unused")
            Rails::Command.invoke "unused_routes", ARGV
          else
            super
          end
        end
      end

      desc "routes", "List all the defined routes"
      def perform(*)
        boot_application!
        require "action_dispatch/routing/inspector"

        say inspector.format(formatter, routes_filter)
      end

      private
        def inspector
          ActionDispatch::Routing::RoutesInspector.new(Rails.application.routes.routes)
        end

        def formatter
          if options.key?("expanded")
            ActionDispatch::Routing::ConsoleFormatter::Expanded.new
          else
            ActionDispatch::Routing::ConsoleFormatter::Sheet.new
          end
        end

        def routes_filter
          options.symbolize_keys.slice(:controller, :grep)
        end
    end
  end
end

Version data entries

39 entries across 39 versions & 5 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/railties-7.1.3.4/lib/rails/commands/routes/routes_command.rb
railties-8.0.1 lib/rails/commands/routes/routes_command.rb
railties-8.0.0.1 lib/rails/commands/routes/routes_command.rb
railties-7.2.2.1 lib/rails/commands/routes/routes_command.rb
railties-7.1.5.1 lib/rails/commands/routes/routes_command.rb
railties-8.0.0 lib/rails/commands/routes/routes_command.rb
railties-7.2.2 lib/rails/commands/routes/routes_command.rb
railties-7.1.5 lib/rails/commands/routes/routes_command.rb
railties-8.0.0.rc2 lib/rails/commands/routes/routes_command.rb
railties-7.2.1.2 lib/rails/commands/routes/routes_command.rb
railties-7.1.4.2 lib/rails/commands/routes/routes_command.rb
railties-8.0.0.rc1 lib/rails/commands/routes/routes_command.rb
railties-7.2.1.1 lib/rails/commands/routes/routes_command.rb
railties-7.1.4.1 lib/rails/commands/routes/routes_command.rb
railties-8.0.0.beta1 lib/rails/commands/routes/routes_command.rb
omg-railties-8.0.0.alpha9 lib/rails/commands/routes/routes_command.rb
omg-railties-8.0.0.alpha8 lib/rails/commands/routes/routes_command.rb
omg-railties-8.0.0.alpha7 lib/rails/commands/routes/routes_command.rb
omg-railties-8.0.0.alpha4 lib/rails/commands/routes/routes_command.rb
omg-railties-8.0.0.alpha3 lib/rails/commands/routes/routes_command.rb