Skip to content

Commit

Permalink
Add patch for config/boot and install script to apply it
Browse files Browse the repository at this point in the history
  • Loading branch information
faqndo97 committed Dec 31, 2023
1 parent 6f15c3f commit e92740e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/colorized_routes/patches/boot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails/commands/routes/routes_command'

::Rails::Command::RoutesCommand.class_eval do
class_option :colorized, type: :boolean, aliases: "-C", desc: "Print routes with a colorized version"
end
3 changes: 3 additions & 0 deletions lib/colorized_routes/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ module ColorizedRoutes
class Railtie < ::Rails::Railtie
::Rails::Command::RoutesCommand.prepend ColorizedRoutes::Command::RoutesCommand

rake_tasks do
load 'tasks/colorized_routes.rake'
end
end
end
4 changes: 4 additions & 0 deletions lib/install/install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BOOT_PATH = Rails.root.join("config/boot.rb")

say "Load `rails routes` patch on boot"
append_to_file BOOT_PATH.to_s, "require 'colorized_routes/patches/boot'"
6 changes: 6 additions & 0 deletions lib/tasks/colorized_routes.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace :colorized_routes do
desc "Setup Colorized Routes for the app"
task :install do
system RbConfig.ruby, "./bin/rails", "app:template", "LOCATION=#{File.expand_path("../install/install.rb", __dir__)}"
end
end
3 changes: 3 additions & 0 deletions test/dummy/config/boot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
$LOAD_PATH.unshift File.expand_path("../../../lib", __dir__)

require 'rails/command'
require 'colorized_routes/patches/boot'

0 comments on commit e92740e

Please sign in to comment.