Skip to content

Commit

Permalink
feat: rake task to list all routes
Browse files Browse the repository at this point in the history
  • Loading branch information
swiknaba committed May 19, 2024
1 parent 4536429 commit 74d04dd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/cli/commands/new_app/files/rakefile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def self.content
# frozen_string_literal: true
require "rake"
require_relative "app"
Dir.glob("#{Kirei::GEM_ROOT}/lib/tasks/**/*.rake").each { import(_1) }
Dir.glob("lib/tasks/**/*.rake").each { import(_1) }
Expand Down
26 changes: 26 additions & 0 deletions lib/tasks/routes.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# typed: false
# frozen_string_literal: true

require_relative("../kirei")

namespace :kirei do
desc "Prints all available routes"
task :routes do
router = Kirei::Routing::Router.instance

longest_path = router.routes.keys.map(&:length).max

routes_by_controller = router.routes.values.group_by(&:controller)

puts "\n"

routes_by_controller.each do |controller, routes|
puts "#{controller}:"
routes.each do |route|
verb = route.verb.serialize.upcase.ljust(7 + 3) # 7 is the length of the longest verb
puts "#{verb} #{route.path.ljust(longest_path + 1)} => ##{route.action}"
end
puts "\n"
end
end
end
3 changes: 3 additions & 0 deletions spec/test_app/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
# frozen_string_literal: true

require "rake"
require_relative "app"

Dir.glob("#{Kirei::GEM_ROOT}/lib/tasks/**/*.rake").each { import(_1) }

Dir.glob("lib/tasks/**/*.rake").each { import(_1) }

0 comments on commit 74d04dd

Please sign in to comment.