From 57b92fe9790cf3cf4a1e04d794b41b3c3eec6ef3 Mon Sep 17 00:00:00 2001 From: Guillermo Guerrero Date: Fri, 12 May 2023 17:27:37 +0200 Subject: [PATCH 1/2] decide when run rake or rails routes. --- README.md | 4 ++-- lib/annotate/annotate_routes.rb | 2 +- lib/annotate/annotate_routes/header_generator.rb | 3 ++- lib/annotate/parser.rb | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index abf325ffa..85a899211 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ when using `SpatialAdapter`, `PostgisAdapter` or `PostGISAdapter`: # path :geometry line_string, 4326 ``` -Also, if you pass the `-r` option, it'll annotate `routes.rb` with the output of `rake routes`. +Also, if you pass the `-r` option, it'll annotate `routes.rb` with the output of `rake/rails routes`. ## Upgrading to 3.X and annotate models not working? @@ -217,7 +217,7 @@ you can do so with a simple environment variable, instead of editing the If --w option is used, the same text will be used as opening and closing --wo, --wrapper-open STR Annotation wrapper opening. --wc, --wrapper-close STR Annotation wrapper closing - -r, --routes Annotate routes.rb with the output of 'rake routes' + -r, --routes Annotate routes.rb with the output of 'rake/rails routes' --models Annotate ActiveRecord models -a, --active-admin Annotate active_admin models -v, --version Show the current version of this gem diff --git a/lib/annotate/annotate_routes.rb b/lib/annotate/annotate_routes.rb index c9a2218ac..56c6a342c 100644 --- a/lib/annotate/annotate_routes.rb +++ b/lib/annotate/annotate_routes.rb @@ -4,7 +4,7 @@ # # # -# Prepends the output of "rake routes" to the top of your routes.rb file. +# Prepends the output of "rake/rails routes" to the top of your routes.rb file. # Yes, it's simple but I'm thick and often need a reminder of what my routes # mean. # diff --git a/lib/annotate/annotate_routes/header_generator.rb b/lib/annotate/annotate_routes/header_generator.rb index b1c93acf7..069c3a68d 100644 --- a/lib/annotate/annotate_routes/header_generator.rb +++ b/lib/annotate/annotate_routes/header_generator.rb @@ -16,7 +16,8 @@ def generate(options = {}) private def routes_map(options) - result = `rake routes`.chomp("\n").split(/\n/, -1) + command = Rails.version.first.to_i > 5 ? `rails routes` : `rake routes` + result = command.chomp("\n").split(/\n/, -1) # In old versions of Rake, the first line of output was the cwd. Not so # much in newer ones. We ditch that line if it exists, and if not, we diff --git a/lib/annotate/parser.rb b/lib/annotate/parser.rb index 3f5ebdb00..5feaad3ca 100644 --- a/lib/annotate/parser.rb +++ b/lib/annotate/parser.rb @@ -145,7 +145,7 @@ def add_options_to_parser(option_parser) # rubocop:disable Metrics/MethodLength, option_parser.on('-r', '--routes', - "Annotate routes.rb with the output of 'rake routes'") do + "Annotate routes.rb with the output of 'rake/rails routes'") do env['routes'] = 'true' end From 6720020e7f23d0326235df54c348d0758ee16a15 Mon Sep 17 00:00:00 2001 From: Guillermo Guerrero Date: Fri, 12 May 2023 17:38:20 +0200 Subject: [PATCH 2/2] require activerecord. --- lib/annotate/annotate_routes/header_generator.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/annotate/annotate_routes/header_generator.rb b/lib/annotate/annotate_routes/header_generator.rb index 069c3a68d..94665151f 100644 --- a/lib/annotate/annotate_routes/header_generator.rb +++ b/lib/annotate/annotate_routes/header_generator.rb @@ -1,3 +1,4 @@ +require 'active_record' require_relative './helpers' module AnnotateRoutes @@ -16,7 +17,7 @@ def generate(options = {}) private def routes_map(options) - command = Rails.version.first.to_i > 5 ? `rails routes` : `rake routes` + command = ActiveRecord.version.to_s.first.to_i > 5 ? `rails routes` : `rake routes` result = command.chomp("\n").split(/\n/, -1) # In old versions of Rake, the first line of output was the cwd. Not so