Sha256: fbd08e06dee96585789236100fcb1974254f410d530f49b3a9690e47d4fbec70

Contents?: true

Size: 1014 Bytes

Versions: 3

Compression:

Stored size: 1014 Bytes

Contents

module Karafka
  # Karafka framework Cli
  class Cli
    # Routes Karafka Cli action
    class Routes < Base
      desc 'Print out all defined routes in alphabetical order'
      option aliases: 'r'

      # Print out all defined routes in alphabetical order
      def call
        routes.each do |route|
          puts "#{route.topic}:"
          Karafka::Routing::Route::ATTRIBUTES.each do |attr|
            print(attr.to_s.capitalize, route.public_send(attr))
          end
        end
      end

      private

      # @return [Array<Karafka::Routing::Route>] all routes sorted in alphabetical order
      def routes
        Karafka::App.routes.sort do |route1, route2|
          route1.topic <=> route2.topic
        end
      end

      # Prints a given value with label in a nice way
      # @param label [String] label describing value
      # @param value [String] value that should be printed
      def print(label, value)
        printf "%-18s %s\n", "  - #{label}:", value
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
karafka-0.5.0.3 lib/karafka/cli/routes.rb
karafka-0.5.0.2 lib/karafka/cli/routes.rb
karafka-0.5.0.1 lib/karafka/cli/routes.rb